eBay Sandbox API | Guest Place order | Error: empty reply from server - ebay-api

I am using eBay Sandbox API to place the order, I have generated the session id and pass to this url https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/{session_id}/place_order
My php curl is
$header = array('Accept: application/json',
'Authorization: Bearer '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-ENDUSERCTX:affiliateCampaignId=<ePNCampaignId>,affiliateReferenceId=<referenceId>'
);
$placeOrderUrl = "https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/{checkoutSessionId}/place_order";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($placeOrderUrl));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);
$information = curl_getinfo($ch);
print_r($information);
echo '<br/>';
echo 'Error Code '.curl_errno($ch).'<br/>';
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo '<br/>';
print_r(json_decode($response,true));
but i am getting the error
Error Code 52
ERROR:Empty reply from server
and here is the output array
Array(
[url] => https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/v1|5000704767|133511112/place_order
[content_type] =>
[http_code] => 100
[header_size] => 25
[request_size] => 2146
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.314586
[namelookup_time] => 2.3E-5
[connect_time] => 0.073967
[pretransfer_time] => 0.236347
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.314579
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 66.135.212.84
[certinfo] => Array ()
[primary_port] => 443
[local_ip] => 198.71.236.80
[local_port] => 37903
[request_header] => POST /buy/order/v1/guest_checkout_session/v1|5000704767|133511112/place_order HTTP/1.Host: api.sandbox.ebay.comAccept: application/json
Authorization: Bearer {token}
Content-Type: application/json
X-EBAY-C-ENDUSERCTX:affiliateCampaignId=,affiliateReferenceId=
Expect: 100-continue)

You have to urlencode the sessionId: v1|5000704767|133511112 should be v1%7C5000704767%7C133511112

Related

OpenSSL SSL_read: error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac, errno 0

I am running this piece of code on a Apache server in order to retrieve few zip files.
$ch = curl_init("https://opendata-rncs.inpi.fr/services/diffusion/document/get?
listeIdFichier=" . $listFilesId);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$headers = array(
"Cookie: " . $token,
'login: xxxxxxxxxx',
'password: '. $this->tokenApiInpi,
"Content-Type: application/json",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$raw_file_data = curl_exec($ch);
if(curl_errno($ch)) {
echo 'error:' . curl_error($ch);
}
curl_close($ch);
On my local machine it works fine, running on a simple symfony server.
But on the Apache production server, I ve got this error:
OpenSSL SSL_read: error:1408F119:SSL
routines:ssl3_get_record:decryption failed or bad record mac, errno 0
Sometimes it works, but it's rare.
OpenSSL 1.1.1f 31 Mar 2020
cURL Information => 7.68.0
curl_getInfo()
array:37 [
"url" => "https://opendata-rncs.inpi.fr/services/diffusion/document/get?listeIdFichier=229514679,230627776,222612310,233647858"
"content_type" => "application/zip"
"http_code" => 200
"header_size" => 705
"request_size" => 291
"filetime" => -1
"ssl_verify_result" => 0
"redirect_count" => 0
"total_time" => 0.462636
"namelookup_time" => 0.003911
"connect_time" => 0.008549
"pretransfer_time" => 0.038412
"size_upload" => 0.0
"size_download" => 703824.0
"speed_download" => 1523428.0
"speed_upload" => 0.0
"download_content_length" => 5362987.0
"upload_content_length" => -1.0
"starttransfer_time" => 0.430148
"redirect_time" => 0.0
"redirect_url" => ""
"primary_ip" => "81.252.220.78"
"certinfo" => []
"primary_port" => 443
"local_ip" => "10.1.2.7"
"local_port" => 53494
"http_version" => 2
"protocol" => 2
"ssl_verifyresult" => 0
"scheme" => "HTTPS"
"appconnect_time_us" => 38371
"connect_time_us" => 8549
"namelookup_time_us" => 3911
"pretransfer_time_us" => 38412
"redirect_time_us" => 0
"starttransfer_time_us" => 430148
"total_time_us" => 462636
]

Trouble Connecting with BigCommerce API

I'm using the following to try and test a GET request on the BigCommerce API locally, but I'm getting a "Failed to connect to api.bigcommerce.com port 443: Connection refused". Any help would be appreciated. Thanks in advance.
$api_url = 'https://api.bigcommerce.com/stores/STORE-HASH/v3/customers';
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
"X-Auth-Client: xxxxxxxx",
"X-Auth-Token:xxxxxxxx"
);
$chbig = curl_init();
curl_setopt($chbig, CURLOPT_URL, $api_url);
curl_setopt($chbig, CURLOPT_TIMEOUT, 60);
curl_setopt($chbig, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $chbig, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $chbig, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $chbig, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($chbig); //execute request
$http_status = (string) curl_getinfo($chbig, CURLINFO_HTTP_CODE);
if(curl_errno($chbig))
{
echo 'Curl error: ' . curl_error($chbig);
}
curl_close($chbig);
echo "<pre>";
print_r($http_status);
print_r($result);```
I really like to use Postman for testing out my API requests. You may want to download that as well, if you have not already.
Here is the code that I am using to connect to my customers
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.bigcommerce.com/stores/{STORE_HASH}/v3/customers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"X-Auth-Token: {TOKEN}",
"X-Auth-Client:{CLIENT_ID}"
),
));
$response = curl_exec($curl); // makes the request
curl_close($curl);
echo $response;
You may be having issues due to the Accept and/or Content-type headers. I would remove those headers and only use the 'X-Auth-Token' and 'X-Auth-Client' headers for GET requests. Good luck!

How to create Sales order attachment in Zoho Books with using Sales Order attachment API?

I am trying to create Sales Order attachment in Zoho Books using Sales Order attachment API but it gives me error like "[code] => 33003 [message] => Receipt not attached".
If I try API with postman it works.
Below is my API call copied from postman.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL =>
"https://books.zoho.com/api/v3/salesorders/**********/attachment?
organization_id=********",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-
Disposition: form-data; name=\"attachment\";
filename=\"D:\\wamp\\www\\*****\\01-30-18 E01301811384413.pdf\"\r\nContent-
Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--
",
CURLOPT_HTTPHEADER => array(
"Authorization: *********************",
"Cache-Control: no-cache",
"Content-Type: application/json",
"Postman-Token: e1141774-32e0-09f1-059b-6d2ee0c44095",
"content-type: multipart/form-data; boundary=----
WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Any help is appreciated.
The code generated by postman is not working for any file upload API's.
Please try this below php code snippet for uploading file to Zoho Books.
<?php
$file_name_with_full_path = '/Users/Admin/Desktop/1.png';
$request_url = 'https://books.zoho.com/api/v3/salesorders/******/attachment';
if (function_exists('curl_file_create')) { // php 5.6+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '#' . realpath($file_name_with_full_path);
}
$post = array(
'authtoken' => '*******',
'organization_id' => '*******',
'attachment'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($ch);
curl_close ($ch);
print_r($r);
?>

areto api payment gateway

I am trying to implement the Areto API payment gateway, but it returns response with authentication error such as :
Authentication failed - invalid ID/Session/IP combination.
I am try to first time implement (this type) payment gateway.
how to implement Areto API payment gateway.
Just have use the code like this:
<?php
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$transaction = array(
"Authentication" => array(
"Id" => $api_id,
"Session" => $api_session
),
"Order" => array(
"OrderId" => "TESTSALE",
"Amount" => "0.01",
"CurrencyCode" => "EUR"
),
"CardDetails" => array(
"CCVC" => "123",
"CCExpiryMonth" => "01",
"CCExpiryYear" => "2017",
"CCName" => "Wdp",
"CCSurname" => "Tech",
"CCNumber" => '4200000000000000',
"CCType" => "VISA",
"CCAdress" => "542, surya nagar",
"ClientCity" => "Jaipur",
"ClientCountryCode" => "US",
"ClientZip" => "302017",
"ClientEmail" => "wdpjaipur#gmail.com",
"ClientExternalIdentifier" => "MytestUserName1",
"ClientIP" => "162.158.50.205",
"ClientPhone" => "1234567890"
)
);
$data_string = json_encode($transaction);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$http_status . PHP_EOL;
$responceData = json_decode($response, TRUE);
echo '<pre>';
print_r($responceData);die;
?>
This part of the API is not very well documented, but after we found this question we were finally able to find a way to solve the problem:
The key is to have all the properties you want to send concatenated into a string divided by & characters and send them as plain text via POST.
If you want to try it out in Postman:
1) enter the properties as url parameters
2) copy the string from the url
3) and paste it in the request body, setting the type to plain text.
error_reporting(1);
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$clientIP = $_SERVER['REMOTE_ADDR'];
$request_arr = array(
'Id'=>$api_id,
'Session'=>$api_session,
'OrderId'=>time(),
'Amount'=>'4.0',
'CurrencyCode'=>'EUR',
'CCVC'=>'123',
'CCExpiryMonth'=>'12',
'CCExpiryYear'=>'2017',
'CCName'=>'wdp',
'CCSurname'=>'technologies',
'CCNumber'=>'4200000000000000',
'CCType'=>'VISA',
'CCAddress'=>'surya nagar',
'ClientCity'=>'Ajmer',
'ClientCountryCode'=>'IN',
'ClientZip'=>'302018',
'ClientEmail'=>'wdpjaipur1#gmail.com',
'ClientExternalIdentifier'=>'Wdp tech',
'ClientIP'=>$clientIP,
'ClientPhone'=>'1234567890',
'ClientDOB'=>'1989-11-05'
);
$ch = curl_init();
$post_variables = '';
foreach ($request_arr as $key => $value) {
$post_variables .= "{$key}={$value}&";
}
$post_variables = rtrim($post_variables, '&');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_variables);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$responceData = json_decode($response, TRUE);

How to post JSON to an API endpoint?

I am using Hertz Api Reservation vehicle lookup service to get a list of vehicles with provided itinerary information. The documentation to this specific service can be found here
NOTE: They require you to have an access token to access their developer docs but you can easily get one by just filling out the form. Alternatively, you can just use the one I have below().
Here is the code that I used
$action_uri = 'https://www.hertz.co.nz/rentacar/rest/home/form';
$post_fields = array(
'accessToken' => '1616634772671643728-8915933508415978751',
'ageSelector' => '21',
'continueButton' => 'continue',
'dropoffDay' => '6/6/2013',
'dropoffTime' => '9:00',
'pickupDay' => '5/6/2013',
'pickupHiddenEOAG' => 'AKLT50',
'pickupLocation' => 'Auckland Airport',
'pickupTime' => '09:00'
);
$data_string = json_encode($post_fields);
$ch = curl_init($action_uri);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/Cookiejar.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/Cookiejar.txt');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));
$content = curl_exec($ch);
$headers = curl_getinfo($ch);
$error_number = curl_errno($ch);
$error_message = curl_error($ch);
curl_close($ch);
print_r($content);
var_dump($headers);
var_dump($error_number);
var_dump($error_message);
According to their documentation, I need to submit the POST parameters in JSON format. Because of that, I set CURLOPT_HTTPHEADER to what you see above.
My problem is that I am getting garbled data from $content like this
‹Eͱ‚0৸t щÕÉÅã`B8¤±´M[ ðº]¿Þýÿƒ¶î"Er˜½üÌ¿Iø ‡M{#µÎi›S:ŽcÒ¢qSR©DNÔ t¬bÆÍÀW’¶ªÃïý–zV5ú˜Sšz]ÂéÐZöÂÿÖK±Š·¯Þq¯áÁ;„´#f|'`00ÁkÐûŽ;Åõþ̲cIÖ„2´EË¥Åpó
This is the output of $headers
array
'url' => string 'https://www.hertz.co.nz/rentacar/rest/home/form' (length=47)
'content_type' => string 'application/json' (length=16)
'http_code' => int 400
'header_size' => int 479
'request_size' => int 694
'filetime' => int -1
'ssl_verify_result' => int 20
'redirect_count' => int 0
'total_time' => float 1.078
'namelookup_time' => float 0
'connect_time' => float 0.25
'pretransfer_time' => float 0.75
'size_upload' => float 261
'size_download' => float 187
'speed_download' => float 173
'speed_upload' => float 242
'download_content_length' => float -1
'upload_content_length' => float 0
'starttransfer_time' => float 1.078
'redirect_time' => float 0
'certinfo' =>
array
empty
As you can see, I got http_code 400 which is a Bad Request.
Any idea why this is? Am I doing the posting of a JSON variable to an API right?
It`s gziped answer. Add CURLOPT_ENCODING
curl_setopt($ch, CURLOPT_ENCODING, '');
I think these are old links now as I can't hertz documentation at these links