skip to Main Content

I’m trying to use the ebay REST-API for the first. I am simply trying to generate an access_token using the client credentials grant-request. I followed the instructions here https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html

HTTP method:   POST
  URL (Sandbox): https://api.sandbox.ebay.com/identity/v1/oauth2/token

  HTTP headers:
    Content-Type = application/x-www-form-urlencoded
    Authorization = Basic <B64-encoded_oauth_credentials>

  Request body (wrapped for readability):
    grant_type=client_credentials&
    redirect_uri=<RuName-value>&
    scope=https://api.ebay.com/oauth/api_scope

I’m getting this error: {'error': 'invalid_client', 'error_description': 'client authentication failed'} and my code looks like this:

path = 'https://api.sandbox.ebay.com/'
app_json = 'application/json'

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': base64.b64encode(b'Basic CLIENT_ID:CLIENT_SECRET')

}

payload = 'grant_type=client_credentials&redirect_uri=Searchez&scope=https://api.ebay.com/oauth/api_scope'

def get_oath_token():
    url = 'https://api.sandbox.ebay.com/identity/v1/oauth2/token'
    r = requests.post(url, headers=headers, data=payload)
    print(r.json())

get_oath_token()

What do I have configured incorrectly? Thanks.

2

Answers


  1. In your code, i can see sandbox endpoint URI but in the request body scope, you have used production URL, instead of sandbox

    Login or Signup to reply.
  2. You’re base64encoding “Basic ” and shouldn’t be.
    The doc says just encode your Client ID + “:” + Client Secret, and leave the word “Basic” and the space that follows it alone.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search