question

maja3981 avatar image
0 Likes"
maja3981 asked ·

Product search issue

I'm trying to search the product list via the REST API and can't seem to get past the token phase. If I use the basic scope ( https://api.ebay.com/oauth/api_scope), the token gets created, but I get an error when I try to call /product_summary/search. It returns: The remote server returned an error: (401) Unauthorized. Response from Server ( https://api.ebay.com/commerce/catalog/v1_beta/product_summary/search?q=Nikon&category_ids=31388): { "errors" : [ { "errorId" : 1001, "domain" : "OAuth", "category" : "REQUEST", "message" : "Invalid access token", "longMessage" : "Invalid access token. Check the value of the Authorization HTTP request header."; } ] } However, if I try to add either "/sell.inventory" or "/commerce.catalog.readonly" to the scope (per the documentation at https://developer.ebay.com/api-docs/commerce/catalog/resources/product_summary/methods/search), I get an error getting the token - "{"error":"invalid_scope","error_description":"The requested scope is invalid, unknown, malformed, or exceeds the scope granted to the client"}". Any ideas what I'm missing? Both of the more specific scopes are listed when I show the OAuth Scopes on my Application Keys page ( https://developer.ebay.com/my/keys). What am I doing wrong? Thanks, Matt Side note - trying to repost this without code to see if it can skip moderation (been 5 days) and get posted so that I can try to move on from this issue.
oauth2catalog api
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.

maja3981 avatar image
0 Likes"
maja3981 answered ·
@eram_developersupport - Thanks for the feedback. I am using the application token in my tests. How should I go about getting a user token? Everything that I've found about them, including https://developer.ebay.com/my/auth?env=sandbox∈dex=0, indicates that I need a redirect URL, which I don't have. If I go to the above link, it's set to "Auth'n'Auth" by default. If I select "OAuth", it opens the lower section and starts asking about the redirects. Everything that I'm doing is a background process, and needs to be capable of running without a UI. Here's the code that I have so far - how do I get my call to (new EBayRestClient()).GetProducts() working properly? public class EBayRestClient { private class AccessToken { public string access_token { get; set; } public string token_type { get; set; } public int expires_in { get; set; } } private DateTime? TokenIssued { get; set; } private AccessToken OAuthToken { get; set; } private async Task GetToken() { if( TokenIssued.HasValue ) { if( (DateTime.UtcNow - TokenIssued.Value).TotalSeconds < 0.9 * OAuthToken.expires_in ) { return; } } var requestBody = string.Format( "grant_type=client_credentials≻ope= https://api.ebay.com/oauth/api_scope"; ); var bytes = Encoding.UTF8.GetBytes( requestBody ); var tokenRequest = WebRequest.CreateHttp( " https://api.sandbox.ebay.com/identity/v1/oauth2/token"; ); tokenRequest.ContentType = "application/x-www-form-urlencoded"; tokenRequest.Headers.Add( HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String( Encoding.UTF8.GetBytes( "[client-id]" + ":" + "[client-secret]" ) ) ); tokenRequest.ContentLength = bytes.Length; tokenRequest.Method = "POST"; using( var requestStream = await tokenRequest.GetRequestStreamAsync() ) { await requestStream.WriteAsync( bytes, 0, bytes.Length ); requestStream.Close(); try { HttpWebResponse response; response = (HttpWebResponse)(await tokenRequest.GetResponseAsync()); if( response.StatusCode == HttpStatusCode.OK ) { Stream responseStream = response.GetResponseStream(); string responseStr = await new StreamReader( responseStream ).ReadToEndAsync(); OAuthToken = JsonConvert.DeserializeObject ( responseStr ); TokenIssued = DateTime.UtcNow; } } catch( Exception ex ) { Debug.WriteLine( ex.FullInnerMessage() ); } } } public async Task GetProducts() { await GetToken(); if( OAuthToken == null ) { return; } var tokenRequest = WebRequest.CreateHttp( " https://api.ebay.com/commerce/catalog/v1_beta/product_summary/search?q=Nikon&category_ids=31388"; ); tokenRequest.Headers.Add( HttpRequestHeader.Authorization, "Bearer " + OAuthToken.access_token ); tokenRequest.ContentLength = 0; tokenRequest.Method = "GET"; try { HttpWebResponse response; response = (HttpWebResponse)(await tokenRequest.GetResponseAsync()); if( response.StatusCode == HttpStatusCode.OK ) { Stream responseStream = response.GetResponseStream(); string responseStr = await new StreamReader( responseStream ).ReadToEndAsync(); Debug.WriteLine( responseStr ); } } catch( Exception ex ) { Debug.WriteLine( ex.FullInnerMessage() ); } } }
· Share
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.

eram_developersupport avatar image
0 Likes"
eram_developersupport answered ·
Hi @maja3981 , Have you taken OAuth User token? If not, please use OAuth user token not the application token and let me know if issue still persists. And could you please verify from the dev portal that you have the above scope you mentioned in your OAuth scope. Here the doc: https://developer.ebay.com/api-docs/static/oauth-scopes.html Best Regards, eBay Developer Support
· Share
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.

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.