11-28-2023 07:05 AM
My code is the following:
$guzzleClient = new \GuzzleHttp\Client();
$response = $guzzleClient->post('https://api.sandbox.ebay.com/identity/v1/oauth2/token', [
'headers' => [
'Authorization' => 'Basic ' . $oauthToken,
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => 'application/json',
],
'form_params' => [
'grant_type' => 'client_credentials',
'scope' => 'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly'
]
]);
I get t he following response:
"{"error":"invalid_scope","error_description":"The requested scope is invalid, unknown, malformed, or exceeds the scope granted to the client"}"
But https://api.ebay.com/oauth/api_scope is the only scope that works.
This is the OathScopes window:
11-28-2023 09:24 AM
The displayed code is mixing a user-token call with application-token parameters.
https://developer.ebay.com/api-docs/static/authorization_guide_landing.html
When using an API to browse, like a guest, no access is required to get into a user account, so the generalized "client credential" for the application is sufficient. A token will be issued that must be renewed every two hours.
https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
When accessing a user account to manage fulfillment, a "user authentication" process is required to obtain permission and to mint a token to access the user's eBay account. The process starts with obtaining a 5-minute consent from the user.
https://developer.ebay.com/api-docs/static/oauth-consent-request.html
That consent is then converted to an 18-month user token, that requires a 2-hour refresh token.
https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html
11-29-2023 03:24 AM
Hi, thanks for reply. My goal is to retreive the orders by REST API. I still dont understand what I'm doing wrong.
If understand, I have to first make
GET https://auth.sandbox.ebay.com/oauth2/authorize
then.
POST https://api.sandbox.ebay.com/identity/v1/oauth2/token
This is my new code (for the first request):
$base64auth = base64_encode($appId . ':' . $clientId);
// get user token with guzzle
$params = [
'client_id' => $clientId,
'redirect_uri' => $redirectUri,
'response_type' => 'code',
'prompt' => 'login',
'locale' => 'it_IT',
'scope' => 'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
];
$url = 'https://auth.sandbox.ebay.com/oauth2/authorize';
$fullUrl = $url . '?' . http_build_query($params);
$client = new \GuzzleHttp\Client();
$response = $client->get($fullUrl);
however I get the following error
GuzzleHttp\Exception\ConnectException with message 'cURL error 6: Could not resolve host: auth.it.sandbox.ebay.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://auth.it.sandbox.ebay.com/oauth2/authorize?client
What am I doing wrong?