09-14-2023 08:45 AM - last edited on 09-14-2023 09:38 AM by kh-ornesh
hi, I have this real simple test.php file for the purpose of pulling down a list of orders, but I only want a list of orders that are paid and awaiting despatch. I am building an inventory management tool and want to quickly generate picking lists from the eBay orders. the code I am testing is below, and is there any way to have a permanent access token as it keeps expiring every hour so I have to paste in a new one.
<?php // Your eBay API credentials
$api_endpoint = 'https://api.ebay.com/sell/fulfillment/v1/order';
$access_token = ....
// Set up headers for the API request
$headers = array(
'Authorization: Bearer ' . $access_token,
'Content-Type: application/json',
);
// Make the API request to eBay to retrieve orders/items waiting to be dispatched
$ch = curl_init($api_endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
// Handle API request error
echo json_encode(['error' => 'API request failed']);
exit();
}
// Process the response and calculate totals
$data = json_decode($response, true);
if (!isset($data['orders'])) {
// Handle the case where "orders" key is not present in the API response
echo json_encode(['error' => 'No orders found']);
exit();
}
echo "<pre>";
print_r($data);
echo "</pre>";
09-14-2023 09:53 AM
I have asked the moderators to remove your $access_token. When posting an example, just post a little of the start and end so we can see the encoding you are using, but without exposing the entire token.
$access_token = 'v^1.1#i^1#p^3#f^0#r...PpOggAAA=';
You will need to organize your program to retrieve the user refresh token when the access token expires. The user OAuth token expires after 2 hours, and your application must renew it programmatically by using a private refresh token for the same user, which typically expires after 18 months.
The process is shown here:
https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html
Details for each step can be found in the left side menu.
I have posted a PHP example for coining the simpler application client token. You could probably expand on it to refresh a user token.