cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error Searching Catalog for UPC Match

Hello! Any help would be greatly greatly appreciated!!

 

I am trying to search the eBay catalog for a match with a UPC. In the example code below, I have just tried to search for the Big Bang Theory Season 1 DVD via it's UPC. I'm using this UPC as it's common and obviously within the eBay catalog. 

 

However, I am constantly getting the following error. I've tried a bunch of things for a couple days but still can't get it to work.

 

Error message: 

Failed to get access token: 400
{'error': 'invalid_scope', 'error_description': 'The requested scope is invalid, unknown, malformed, or exceeds the scope granted to the client'
}

 

Code I am using:

import requests
import base64

# Your eBay sandbox credentials
credentials = {
"client_id": "[ ]",
"client_secret": "[ ]"
}

# Token endpoint
token_url = "https://api.sandbox.ebay.com/identity/v1/oauth2/token"

# Encode client ID and secret for Basic Authentication
auth_header = base64.b64encode(
f"{credentials['client_id']}:{credentials['client_secret']}".encode()
).decode()

# Request headers and payload for the token
headers = {
"Authorization": f"Basic {auth_header}",
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"grant_type": "client_credentials",
"scope": "https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly"
}

# Step 1: Obtain the Access Token
response = requests.post(token_url, headers=headers, data=data)
if response.status_code == 200:
access_token = response.json().get("access_token")
if not access_token:
print("Error: Access token not found in the response.")
print(response.json())
exit()
print("Access token obtained successfully.")
else:
print(f"Failed to get access token: {response.status_code}")
print(response.json())
exit()

# Step 2: Search for the UPC in the eBay Catalog
catalog_search_url = "https://api.sandbox.ebay.com/commerce/catalog/v1_beta/product_summary/search"
search_headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/json"
}
params = {
"q": "9325336046425" # UPC to search for
}

search_response = requests.get(catalog_search_url, headers=search_headers, params=params)

# Check the response
if search_response.status_code == 200:
print("Search response:")
print(search_response.json())
elif search_response.status_code == 404:
print("No results found for the provided UPC.")
else:
print(f"Failed to search for UPC: {search_response.status_code}")
print(search_response.json())
Message 1 of 4
latest reply
3 REPLIES 3

Re: Error Searching Catalog for UPC Match

@rushton_store 

 

The particular UPC for which you are seeking may have been discontinued or delisted by the manufacturer, which happens quite regularly.

 

Since there are only a limited number of UPC numbers available, manufacturers will often delist the UPC from items which are being reissued, revised or removed from distribution.

 

So the UPC in question may no longer be a match for that particular title.

 

For 13 years, I was employed by a nation-wide book seller chain; and we regularly were provided multi-page computer print-out sheets -- sometimes 20 or 30 pages long, with over 30 items per sheet -- of books, DVDs, CDs, and other items, which were being discontinued or delisted by the distributor and/or manufacturer.  Once these items were gathered and packaged up, they were returned to the proper source, and removed from inventory.

 

The manufacturer would then delist and discontinue those UPC numbers, and eventually provide us with similar looking products, but with new additions, inserts, artwork, and so on -- with new UPC numbers.

 

So the UPC for "Big Bang Theory -- Season 1 DVD" for which you are searching, may be one of those delisted and discontinued UPC numbers.

 

Not surprisingly, some UPC and ISBN codes are delisted and discontinued over and over again -- only to show up months later on different items.

 

Again -- there are only a limited number of UPC and ISBN codes available; so manufacturers and publishers are forced to delist old, stale and unsellable inventory quite regularly, in order to re-list those same UPC and ISBN codes on newer merchandise.

 

And, every time a product is revised or "improved," a new UPC or ISBN code is required, just to maintain proper inventory records.

 

It certainly keeps stock clerks and shipping departments busy!

Message 2 of 4
latest reply

Re: Error Searching Catalog for UPC Match

Hello @rushton_store ,

 

You're currently using the scope "https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly" to generate an OAuth Application Token via the Client Credential Flow. However, this scope isn't valid for that flow, which is why you're encountering the error  "The requested scope is invalid, unknown, malformed, or exceeds the scope granted to the client."

 

Furthermore, the Catalog API's search method requires an OAuth User Token generated through the Authorization Code Grant flow. For selling applications, use the scope "https://api.ebay.com/oauth/api_scope/sell.inventory," and for buying applications, use the scope "https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly." while generating the token.

 

Please consult the OAuth User Token Generation and Catalog API search method documentation for more information:
https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html
https://developer.ebay.com/api-docs/commerce/catalog/resources/product_summary/methods/search

 

Best Regards,
eBay Developer Support

Message 3 of 4
latest reply

Re: Error Searching Catalog for UPC Match

ebays system is stupid and confusing.  u can use databases like https://upc.westnet.ca to get more product data 

Message 4 of 4
latest reply