question

youradrenalinefix avatar image
0 Likes"
youradrenalinefix asked

Requesting Help With Shopping API Client Credentials Grant Flow

Hi, I'm using the Shopping API and GetSingleItem to retrieve the TextDescription, Details, ItemSpecifics and ShippingCosts from individual listings and I'm not even sure if I need to specify scopes for these requests.

My implementation works great by sending the APP-ID but now that I am required to upgrade to OAuth verification I don't know where to begin.

I spent a week+ reading all the documentation starting here: https://developer.ebay.com/api-docs/static/ebay-rest-landing.html

including reading about using OAuth to access eBay API's and client credentials grant flow, but it all looks more like theory than actual implementation steps or code samples I could easily implement and I really don't know where to begin.

My questions are:

1.) Referencing this page (https://developer.ebay.com/api-docs/static/oauth-tokens.html)

It says under the heading "Minting access tokens" that "The eBay token service generates, or mints, access tokens via two different grant flows:", then further down under the heading: "The eBay OAuth client libraries" it says: "eBay offers several client libraries that you can use to quickly implement the minting of OAuth tokens in your applications:" which leaves me wondering if the eBay token service generates the access tokens, or if I have to use one of the libraries provided.

2.) Using the PHP code sample provided below, I'm hoping someone could modify this code whereas it will generate the necessary token (Without use of additional libraries) which I could use in my GetSingleItem script to populate my X-EBAY-API-IAF-TOKEN header paramater like so: X-EBAY-API-IAF-TOKEN: getOAuthCreds. (getOAuthCreds being the name of the function below)

3.) If I have to use a library, could someone please suggest which library to use to be able to serve content to all devices as I currently do (And how to install it)?

Basically, I'm serving public knowledge content derived from a GetSingleItem call by passing my APP-ID in the header and am now being forced to upgrade to OAUth which I know nothing about even after studying and struggling with for a week and I still dont know where to begin as far as modifying my code to be able to continue serving this content after July 1st.

Any help is greatly appreciated.

The aforementioned function I created loosely based off of GetSingleItem call code is below:

function getOAuthCreds() {
$endpoint = 'https://api.ebay.com/identity/v1/oauth2/token';

$request = "grant_type=client_credentials";
$request .= "scope=<scopeList>"; //I dont know how to URL encode this string of space-separated scopes to retrieve the TextDescription, Details, ItemSpecifics and ShippingCosts from individual listings

$session = curl_init($endpoint);

curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $request);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$headers = [
"X-EBAY-API-REQUEST-ENCODING: XML", //Not sure if I need this line
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Authorization = Basic <B64-encoded_oauth_credentials>' // I dont know how to provide this
];

curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($session);
curl_close($session);
return $response;
}
oauth2shopping api
· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@sagar_developersupport Please help as Ive spent the past several years learning PHP and have read the documentation but still don't know where to begin or how else to explain what I'm trying to do. Additionally, I don't have the $$ for paid support and don't want to go dark July 1st

Could you please help me get unstuck by showing me an example based off of the code sample I previously provided?

Any "Clues" would be most appreciated as the documentation is not clear to me on how to implement OAuth with the Shopping API GetSingleItem call as I previously explained and I thank you in advance.

0 Likes 0 ·

1 Answer

· Write an Answer
sagar_developersupport avatar image
0 Likes"
sagar_developersupport answered

Hi @youradrenalinefix,

Shopping API requires an Application access token (Client credentials grant) for the execution of API calls. The eBay token service generates, or mints, access tokens via two different grant flows:

Client credentials grant flow mints a new Application access token that you can use to access the resources owned by the application.
Authorization code grant flow mints a new User access token that you can use to access the resources owned by the user.

Ref:https://developer.ebay.com/api-docs/static/oauth-token-types.html

Please, generate an OAuth application token with scope https://api.ebay.com/oauth/api_scope and try to execute the call with an application access token not with a user access token. If you still face the same issue, please let us know.

Ref:
https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
https://developer.ebay.com/devzone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html

Best regards,
eBay Developer Support

· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@AlvisInWales answer below is just what I needed. Thanks
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.