I am trying to use the eBay API to sell an item with python however, I keep on getting this error
{"errors":[{"errorId":2004,"domain":"ACCESS","category":"REQUEST","message":"Invalid request","longMessage":"The request has errors. For help, see the documentation for this API."}]}
I have no idea why it is giving me this and have googled with nothing working.
I have not reached the 5000 limit and do have a valid access code.
This is the link I used for the API https://api.ebay.com/sell/inventory/v1/inventory_item/
When I use the API Explorer (https://developer.ebay.com/DevZone/build-test/test-tool/default.aspx?index=0&api=inventory&call=inventory_item-sku__PUT&variation=json&env=production) I get the same error but it says Can not instantiate value of type
:
{
"errors": [
{
"errorId": 2004,
"domain": "ACCESS",
"category": "REQUEST",
"message": "Invalid request",
"longMessage": "The request has errors. For help, see the documentation for this API.",
"parameters": [
{
"name": "reason",
"value": "Can not instantiate value of type [simple type, class com.ebay.raptor.slrinvapi.app.entities.InventoryItem] from JSON String; no single-String constructor/factory method"
}
]
}
]
}
This is the code but without the client id and client secret:
import requests
import json
import base64
client_id = '#################################'
client_secret = '#################################'
redirect_uri = 'https://amazon.adamkhattab.co.uk/callback.php'
auth_url = 'https://auth.ebay.com/oauth2/authorize'
token_url = 'https://api.ebay.com/identity/v1/oauth2/token'
api_url = 'https://api.ebay.com/sell/inventory/v1/inventory_item'
def get_access_token(client_id, client_secret, redirect_uri):
auth_code = input('Please enter the authorization code: ')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'Basic {base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()}'
}
data = {
'grant_type': 'authorization_code',
'code': auth_code,
'redirect_uri': redirect_uri
}
response = requests.post(token_url, headers=headers, data=data)
access_token = json.loads(response.text)['access_token']
return access_token
def list_item(access_token):
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
data = {
"title": "Bluetooth Speaker",
"condition": "NEW",
"description": "This is a very good speaker and sounds amazing",
"imageUrls": [
"https://amazon.adamkhattab.co.uk/photo.jpg"
],
"price": {
"value": "20.00",
"currency": "GBP"
},
"quantity": 1
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
print(response.text)
auth_url += f'?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope=https://api.ebay.com/oauth/api_scope/sell.inventory'
print(f'Please visit the following URL and authorize the application:n{auth_url}')
access_token = get_access_token(client_id, client_secret, redirect_uri)
list_item(access_token)
2
Answers
I figured it out: I didn't use the SKU parameter in the link which caused the error. This is the new link I used with no errors https://api.ebay.com/sell/inventory/v1/inventory_item/1
In which part exactly did you update the link. I’ve tried updating it on the api_url variable and also
auth_url += f'?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope=https://api.ebay.com/oauth/api_scope/sell.inventory'
and doesn’t seem to work in any of those