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.
Related
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
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 .
I am trying to post a bunch of domains to the godaddy api in order to get information about pricing and availability. However, whenever I try to use curl to execute this request, I am returned nothing. I double checked my key credentials and everything seems to be right on that end. I'm pretty confident the issue is in formatting the postfield, I just don't know how to do that... Thank you to whoever can help in advance!
$header = array(
'Authorization: sso-key ...'
);
$wordsArray = ['hello.com', "cheese.com", "bytheway.com"];
$url = "https://api.godaddy.com/v1/domains/available?checkType=FAST";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_POST, true); //Can be post, put, delete, etc.
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $wordsArray);
$result = curl_exec($ch);
$dn = json_decode($result, true);
print_r($dn);
There are two problems in your code:
Media type of sent data must be application/json (by default this is application/x-www-form-urlencoded), and your PHP app must accept application/json as well:
$headers = array(
"Authorization: sso-key --your-api-key--",
"Content-Type: application/json",
"Accept: application/json"
);
Post fields must be specified as JSON. To achieve this, use the json_encode function:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($wordsArray));
Full PHP code is:
$headers = array(
"Authorization: sso-key --your-api-key--",
"Content-Type: application/json", // POST as JSON
"Accept: application/json" // Accept response as JSON
);
$wordsArray = ["hello.com", "cheese.com", "bytheway.com"];
$url = "https://api.godaddy.com/v1/domains/available?checkType=FAST";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($wordsArray));
$result = curl_exec($ch);
$dn = json_decode($result, true);
print_r($dn);
I want to withdraw the amount in my account, but the account is not found error. I'm successfully sending sms with the same api.
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: Bearer $authToken"
));
echo $result = curl_exec ($ch);
?>
They want like this
curl -X GET --header 'Accept: application/json' --header 'Authorization: Your API key' 'https://platform.clickatell.com/public-client/balance'
Clickatell is not using OAuth2 for authorization, so just remove the "Bearer" from the Authorization. So it should look like this:
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: $authToken"
));
echo $result = curl_exec ($ch);
?>
I'm referencing DigitalOcean's API docs, and they give the following example on how to delete a droplet here:
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" "https://api.digitalocean.com/v2/droplets/[DROPLET_ID]"
How can I write this in PHP curl?
I currently have this:
$ch = curl_init('https://api.digitalocean.com/v2/droplets/18160706');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_API_TOKEN')
);
$result = curl_exec($ch);
echo $result;
But that is not deleting my droplet and is returning (Yes, the droplet id is correct):
{"id":"not_found","message":"The resource you were accessing could not be found."}1
Try This
Change the CUTLOPT_CUSTOMREQUEST to "DELETE" Find More
$ch = curl_init('https://api.digitalocean.com/v2/droplets/18160706');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_API_TOKEN')
);
$result = curl_exec($ch);
echo $result;
You need to set CURLOPT_CUSTOMREQUEST to DELETE as mentioned in the PHP Manual here. Please take some time to read it. The following code should work
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);