Ebay rest api not working for my sandbox account - php

I'm using sandbox and i have generated
Key and token
I have my seller sandbox account .
I'm trying to use sell api (inventory and fullfillment ),but its giving as "A resource (URI) associated with the request could not be resolved" with an error code 3003.
This is the git hub package i'm using in my code .
<?php
// Your token
$authToken = 'AgAAAA**AQAAAA**aAAAAA**MJNfXQ**nY+sHZ2PrBmdj6wVnY+sEZbIEFTWmW7eYbvzFw0uXajYBe6j5ddEO3crLb0oCIHHhc3UFOFYX4+mzwE/6HboGAezWiTXbfJvi034ScYcE0MJ08YHjIt3ciNyu/7OHUnbedLVhNqYjGt/oXL/9bvQPHFcGH/+XS1KfNV+XcdZV/2HJ8n+QNhYawC3lIKeKm6rsH1HH3x9ZECNYvGzPTjL23uaTH53UoshKYPFTi/uq7UO4ZNccE/NdreamfAzGiBTAz6pqL+SnFLrOVn9llPNlMGLO/yVEkAFIdwDF2KduXPVV7ZFTVX9ncfdX04r80Jx4LiMIEnhq5Ftjwq48q+arkDy8Y4T+bf6YPE5UICJnXyGAkJJhSZa5hliV+TRgSFRQkBhCVJf+ZAvVO4CA/TRZxtH77YTSj/Z9HGSzDpavFfh+7IM2lmQxCoHmhHI7e8pta6QBMvKOuq65SH17IW0bYog76dFsDa5OjnjFmFMU4u4dzF9lTFm8lw0TTqjnGja8mh5CZA4OBSsVgkqq4diWacZXKQw5p1tofG4aYbQJ8XNnYBPOAyH2fuSlWmY4Lj+RpBbVmhtj5RA/h/MKUmgN+USGdT0DeKWQMCTVmNaQFJbSEQEzdSRBBQhvqubhnqPG4/95gwanPOxasEbQxMUpnWnF4oOE+eS432P9ILTSOnEZ7Qs70R/GcilczhaPUDJUH9+dFp4DMNVT2P1tiflmBAt';
$header = array('Accept: application/json',
'Authorization: Bearer '.$authToken,
'Content-Type: application/json'
);
$placeOrderUrl =
"https://api.sandbox.ebay.com/sell/fulfillment/v2/order/110181400870-
27973775001";
$body = '{}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($placeOrderUrl));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$information = curl_getinfo($ch);
print_r($response);
?>
I needs to pull the orders as in the doc for the rest api .
I don't know where i'm stuck . Thanks in advance if any one can help me out .

Related

Google Drive v3 API : List all folders working on sandbox but not working on a curl call

Hi so I'm trying to get a list of all the folders I have on a specific drive. It is working when I do tests on google's api explorer here https://developers.google.com/drive/api/v3/reference/files/list but for some reason when I convert it into a php curl call It doesn't fetch any files
Here's my php curl code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER, 'referer here i removed it');
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/drive/v3/files?corpora=allDrives&includeItemsFromAllDrives=true&includeTeamDriveItems=true&q=%27'.$folder_id.'%27%20in%20parents%20and%20mimeType%3D%27application%2Fvnd.google-apps.folder%27&supportsAllDrives=true&key'.$_api_key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authorization: Bearer '.$_access_token;
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo "<pre>";
var_dump(json_decode($result, true));
echo "</pre>";

Google Drive trash Clear Using Php not works

I am trying to clear Trash using php and drive api v3. Code excutes with no error but trash in drive is not deleted. Here is my code please help me to fix this. Thanks For your time.
if($_POST['trash']) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
};
I believe your goal and current situation as follows.
You want to use "Files: emptyTrash" in Drive API v3 using curl of php.
Your access token of $token can be used for using this API.
In order to achieve your goal, how about the following modification?
From:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
To:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Note:
At "Files: emptyTrash", no values are returned.
If $token in your script is the API key which is not the access token, please retrieve the access token and use it. Please be careful this.
Reference:
Files: emptyTrash

Getting transaction details using PayPal REST API (v2) not working

I want to get the full details of a PayPal transaction by its ID using the PayPal REST API.
I tried to do it as the following:
<?php
include("config.php");
// Reference: https://developer.paypal.com/docs/api/get-an-access-token-curl/
$ch = curl_init("https://api.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Accept-Language: en_US"
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_USERPWD, $restapp['client_id'] . ':' . $restapp['secret']);
$result = curl_exec($ch);
curl_close($ch);
$access_token = json_decode($result, true)['access_token'];
// Reference: https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/#on-the-server
$ch = curl_init("https://api.paypal.com/v2/checkout/orders/<transaction_id>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Bearer " . $access_token
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
But this always returns error INVALID_RESOURCE_ID. Please note that I am using the client ID and client secret of my live application, and the transaction ID that I use is a live transaction ID too.
After doing some searches, I've found that https://api.paypal.com/v1/payments/orders/<transaction_id> works instead of https://api.paypal.com/v2/checkout/orders/<transaction_id> .. but v1 doesn't return as much information as v2
What am I doing wrong on the v2 endpoint?
Kind regards.

Curl PHP API Post

i am wanting to post to an API in woocommerce php file i used code below.
$ch = curl_init("https://cors-anywhere.herokuapp.com/https://api.feverfinance.co.za/FTIntegration.svc/BalanceLookup");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic '. base64_encode( $username .":" .$password ) ,
'Accept: application/json, text/plain, */*' ,
'Content-Length: ' . strlen($data_string))
);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT , 0);
$result = curl_exec($ch);
// Check if any error occurred
if(curl_errno($ch))
{
print_r($ch);
print_r($result);
}
$obj = json_decode($result,true);
//Mage::log($result,true);
$tranactionSuccess = $obj['Success'];
$transactionMessage = $obj['Message'];
curl_close($ch);
when i print to console i get ErrorResource id #6.
Please can anyone advise me how to post to API in woocommerce. with the above information that is needed to post to the API
Regards
First you need to activate woocommerce APIs from wordpress backend and generate API keys
Check https://docs.woocommerce.com/document/woocommerce-rest-api/
Then use the following code based on your needs
Example: You need to retrieve product details
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com/wp-json/wc/v3/products/794");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_USERPWD, "consumer_key" . ":" . "consumer_secret");
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Note: consumer_key and consumer_secret was generated by API from backend
and 794 mean product ID
API docs for woocommerce http://woocommerce.github.io/woocommerce-rest-api-docs/

Zoho API V2 Update Record

I am trying to use the Zoho API Version 2 to do a simple record update in Leads. I am using PHP and CURL and my sample code for this call (to update a single field in the record) is as follows:-
$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/" . {valid record id here};
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields),
sprintf('Authorization: Zoho-oauthtoken %s', {valid auth token here})
);
$fields = json_encode([["data" => ["City" => "Egham"]]]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
curl_close($ch);
No matter how I format the JSON, I always get the following returned:
{"code":"INVALID_DATA","details": {"expected_data_type":"jsonobject"},"message":"body","status":"error"}
It is not a matter of invalid auth tokens etc because I have successfully used PHP and CURL with the Zoho API to read data and I decode the JSON returned successfully.
Please could somebody help with passing valid JSON data?
The above code constructs input JSON like this
[{"data":{"City":"Egham"}}]. This JSON is not valid as per the ZOHO CRM APIs(API help).
It should be like this {"data":[{"City":"Egham"}]}.
Change the code like this :
$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/" . {valid record id here};
$fields = json_encode(array("data" => array(["City" => "Egham"])));
// *strlen must be called after defining the variable. So moved headers down to $fields*
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields),
sprintf('Authorization: Zoho-oauthtoken %s', {valid auth token here})
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
curl_close($ch);
You must escape the data into JSON format:
import json
response = requests.post(url, data=json.dumps(data), headers=headers)

Categories