getting Bad Request during opening a querystring file in CURL - php

$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch); // run the whole process
print_r($result);
curl_close($ch);
i also used file_get_conent and fopen but all are returning me BAD REQUEST error,
please help me out
for more detail please see the link below
http://www.uqwibble.com/Phase-2/ach.php

Well assumign the code you posted is accurate then this line is the issue:
$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB
here it looks liek you attemtp to define $URL but when you use it with cURL you are referencing $url. The varibales are case sensitive. Secondly you have $URL: which is not valid you want to use $url =.
Addiitonally i would encode the params like this:
$baseurl = 'https://demo.firstach.com/https/TransRequest.asp';
$params = array(
'Login_ID' => 'someit',
'Transaction_Key' => 'somekey',
'Customer_ID'= => 23,
'Customer_Name' => 'Muhammad Naeem',
'Customer_Address' => 'Address',
'Customer_City' => 'city',
'Customer_State' => 'HI',
'Customer_Zip' => '54000',
'Customer_Phone' => '--',
'Customer_Bank_ID' => '111111118'
'Customer_Bank_Account' => '12345678901234567890'
'Account_Type' => 'Business Checking'
'Transaction_Type' => 'Debit'
'Frequency' => 'Once'
'Number_of_Payments' => 1,
'Effective_Date'=> '12/05/2010',
'Amount_per_Transaction' => '10.00',
'Check_No'=> '',
'Memo'=> '',
'SECCType' => 'WEB'
);
$url = sprintf('%s?%s', $baseurl, http_build_query($params));
That way http_build_query will take care of all your url encoding and you can work with an array before hand so its easy to see whats going on and add/remove/change paramters. Alternatively if its a post request you could jsut use:
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
which will take care of all the parameter encoding and what not directly from the array this way they dont need to be appended manually to the $url.

Related

Bybit - Place Simple Order... (php)

I am using the following 'suggested' code to post a test order to Bybit.
(https://github.com/bybit-exchange/api-usage-examples/blob/master/api_demo/futures/Encryption.php)
<?php
function get_signed_params($public_key, $secret_key, $params) {
$params = array_merge(['api_key' => $public_key], $params);
ksort($params);
//decode return value of http_build_query to make sure signing by plain parameter string
$signature = hash_hmac('sha256', urldecode(http_build_query($params)), $secret_key);
return http_build_query($params) . "&sign=$signature";
}
$params = [
'symbol' => 'BTCUSDT',
'side' => 'Buy',
'order_type' => 'Limit',
'qty' => '1',
'price' => '30000',
'time_in_force' => 'GoodTillCancel',
'reduce_only' => false,
'close_on_trigger' => false,
'timestamp' => time() * 1000,
'position_idx' => 0
];
//$url = 'https://api-testnet.bybit.com/private/linear/order/create';
$url = 'https://api.bybit.com/v2/private/order/create';
$public_key = 'my_key_is_here_in_my_code';
$secret_key = 'my_secret_key_is_here_in_my_code';
$qs=get_signed_params($public_key, $secret_key, $params);
$curl_url=$url."?".$qs;
$curl=curl_init($curl_url);
echo $curl_url;
curl_setopt($curl, CURLOPT_URL, $curl_url);
#curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
#curl_setopt($curl, CURLOPT_PROXY,"127.0.0.1:1087");
$response=curl_exec($curl);
echo $response;
However, I receive the following within the response: validation for 'symbol' failed on the 'symbol' tag"
https://api.bybit.com/v2/private/order/create?api_key=XXXXXX_my_key_XXXXX&close_on_trigger=0&order_type=Limit&position_idx=0&price=30000&qty=1&reduce_only=0&side=Buy&symbol=BTCUSDT&time_in_force=GoodTillCancel×tamp=1647644020000&sign=0e08e9f9be4cf5e4d7b1294d769ab4bf3b5b79ae9f92bab717670b3d95be0672{"ret_code":10001,"ret_msg":"Param validation for 'symbol' failed on the 'symbol' tag","ext_code":"","ext_info":"","result":null,"time_now":"1647644020.389465","rate_limit_status":99,"rate_limit_reset_ms":1647644020387,"rate_limit":100}
Could somebody pls suggest why Bybit is not recognising the 'BTCUSDT' symbol as expected. As everything seems setup on the exchange. Many thanks for your help.
BTCUSDT is not a valid symbol as per the documenation. These are the list of valid symbols that you can use.

Bitshares API - Create an account under a registrar using PHP

I've been trying to create an account under a registrar account on Bitshares Test Net programatically using Graphene API and its blockchain. I read the API documentation and have concluded that the PHP code bellow is what I need to execute to be able to create a new account.
<?php
$url = 'https://testnet.bitshares.eu/';
$array = array(
'jsonrpc' => '2.0',
'method' => 'register_account',
'params' => array(
'name' => 'NEW_ACCOUNT_NAME',
'owner_key' => 'OWNER_KEY',
'active_key' => 'ACTIVE_KEY',
'registrar_account' => 'REGISTRAR_ACCOUNT',
'referrer_account' => 'REGISTRAR_ACCOUNT',
'referrer_percent' => 1,
'broadcast' => 1
),
'id' => 1
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'GraphenePHP/1.0');
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
$response = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($response);
echo '</pre>';
The code above is not working. Also I am not getting any response. I have a feeling that I am missing something or the value of $url is incorrect.
Please help?
This Bitshares testnet link https://testnet.bitshares.eu/ sometimes does not work.
You can simply use real net or install testnet on your side for this.

Why is this PHP script the JSON results when I haven't told it to?

So I'm using the only source I've found for sending a post request to Google QPX API. I want to save it in a json_decoded PHP array, but for some reason the $result = curl_exec($ch); line doesn't work, and the json prints onscreen anyways.
Is there something I'm not understanding that is happening in the cURL? Thanks!
$data = array ( "request" => array(
"passengers" => array(
adultCount => 1
),
"slice" => array(
array(
origin => "BOS",
destination => "LAX",
date => "2015-09-09"),
array(
origin => "LAX",
destination => "BOS",
date => "2015-09-10"),
),
solutions => "10"
),
);
$data_string = json_encode($data);
$ch = curl_init('https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY-API-KEY');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
This:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
CURLOPT_RETURNTRANSFER - TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
http://php.net/curl_setopt
Set this option to true if you want to save the result in a variable.

Php Curl add string file as a post field

I am using mailGun web API and ran into the issue of adding inline files.
Our software creates an image and passes it around as a string. I want to inline that image
The problem that I have is that php curl takes in a file pointer, and not an actual file. I want to avoid writing a tmp file if possible as we have many process that work on the server and would not want to send a bad email
Thanks in advance
MailGun inline Sample:http://documentation.mailgun.net/user_manual.html#inline-image
Code sample that I am using:
function send_inline_image($image) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
curl_setopt($ch,
CURLOPT_POSTFIELDS,
array('from' => 'Excited User <me#samples.mailgun.org>',
'to' => 'sergeyo#profista.com',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!',
'html' => '<html>Inline image: <img src="cid:test.jpg"></html>',
'inline' => $image))
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$image = 'Some image string that we have generated'
send_inline_image($image)
You need to change only the inline parameter of array. I have done it and its works. Inline parameter should be an array instead of string image path. You can do it like this:
function send_inline_image($image) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
curl_setopt($ch,
CURLOPT_POSTFIELDS,
array('from' => 'Excited User <me#samples.mailgun.org>',
'to' => 'sergeyo#profista.com',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!',
'html' => '<html>Inline image: <img src="cid:test.jpg"></html>',
'inline' => array($image)//Use array instead of $image
))
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$image = 'Some image string that we have generated'
send_inline_image($image)
Look at comment "Use array instead of $image"

How to use array values in another array

My Facebook app publishes a story to the user wall with an http post:
$args = array('access_token' => $ACCESS_TOKEN,
'message' => 'testing message',
'picture' => $appin_logo,
'link' => $appin_canvas_url,
'name' => $appin_name,
'caption' => $post_score,
'description' => $post_rfs,
);
$ch = curl_init(); $url = 'https://graph.facebook.com/me/feed'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $data = curl_exec($ch); curl_close($ch);
That works all fine, except for one thing: $post_rfs is an array. I'd like to output its values in a neat way, with a comma after every value i.e.. What should I do?
Thanks in advance.
Try this:
implode(', ', array_values($post_rfs));

Categories