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

Error ID 2004 when selling an item using API

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 it with no solutions.

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)
Message 1 of 1
latest reply
0 REPLIES 0