skip to Main Content

currently I am using eBay Trading API with Python. Thanks to: https://github.com/timotheus/ebaysdk-python

I used https://github.com/luke-dixon/django-ebay-accounts to get tokens for user.

Now, I would like to use Restful API (https://developer.ebay.com/docs#Acc). I don’t think I can use tokens I have already. So, I managed thanks to Getting an Ebay OAuth Token get one. But I think I missing something, because during the process I cannot include info for user (name/password), so, for example https://api.ebay.com/sell/fulfillment/v1/order?limit=10 returns:

{
  "errors": [{
    "errorId": 1100,
    "domain": "ACCESS",
    "category": "REQUEST",
    "message": "Access denied",
    "longMessage": "Insufficient permissions to fulfill the request."
  }]
}

Any idea how can I get a token for the user?

Just snippet of code to make things more clear:

AppSettings = {
            'app_id': EBAY_PRODUCTION_APPID,
            'app_secret': EBAY_PRODUCTION_CERTID,
            'dev_id': EBAY_PRODUCTION_DEVID, 
            'ruName': EBAY_PRODUCTION_RU_NAME 
        }
authHeaderData = AppSettings['app_id'] + ':' + AppSettings['app_secret']
        encodedAuthHeader = base64.b64encode(authHeaderData.encode())

        headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "Authorization": "Basic ".encode() + encodedAuthHeader
        }
body = {
            "grant_type": "client_credentials",
            "redirect_uri": settings.EBAY_PRODUCTION_RU_NAME,
            "scope": "https://api.ebay.com/oauth/api_scope"
        }

        data = urllib.parse.urlencode(body)

        tokenURL = "https://api.ebay.com/identity/v1/oauth2/token"

        response = requests.post(tokenURL, headers=headers, data=body)
        authDict = response.json()

So the request to run I need is:

r = requests.get("https://api.ebay.com/sell/fulfillment/v1/order?limit=10",
                         headers={"Authorization": "{}".format(authDict['access_token']),
                                  "Content-Type": "application/json",
                                  "X-EBAY-C-MARKETPLACE-ID": "EBAY_UK",
                                  "Accept": "application/json"
                                  })

3

Answers


  1. According to this, I believe you are supposed to use the following authorization header:

    headers['Authorization'] = "Bearer " + USER_ACCESS_TOKEN
    

    Where the USER_ACCESS_TOKEN is the massive token generated on this page.

    It looks something like this:

    'v^1.1#i^1#p^3#f^0#I^3#r^0#t^ ...
    ...
    ...
    ...
    ... bfxr8BJtphi2M/oo2xpYo2hiMWxmZt4fVzS7qe2tMXUSAAA='
    

    The Authorization you are using is for requests that aren’t linked to a specific user account (search results, meta data for items, etc.). To make requests that are for specific users (eg. orders or inventory updates), you have to get their permission via their USER_ACCESS_TOKEN.

    If you need help getting the USER_ACCESS_TOKEN let me know and I’ll update.

    Note that I have been trying to do the same thing that you are doing for about 6 hours now, and still haven’t figured it out, so I am not confident in this answer.

    Hope this helps. If you do figure it out, you should post an answer so others can too (ie myself xD).

    eBay definitely wins the gold metal for worst api docs in the history of api docs

    Login or Signup to reply.
  2. The API Explore @ developer.ebay.com has description of HTTP Headers for each RestFul API. E.G. Fulfillment API – getOrdres:

    HTTP Headers
    Authorization:Bearer <OAUTH_token>
    Accept:application/json
    Content-Type:application/json

    Sample code:

    import requests,json
    
    headers = {
     
        "Authorization": "Bearer Type_Your_Token_here_or_Paste_IF_too_long",
        'Accept':'application/json',
        'Content-Type':'application/json'
    }
    
    EndPoint = "https://api.ebay.com/sell/fulfillment/v1/order?filter=orderfulfillmentstatus:%7BNOT_STARTED|IN_PROGRESS%7D"
    
    response = requests.get(EndPoint,headers = headers)
    
    Login or Signup to reply.
  3. https://newbedev.com/ebay-oauth-token-and-refresh-tokens has introduced eBay OAuth token much better than eBay.

    By the way, "grant_type": "client_credentials" is only valid for clients who can on have one scope. https://api.ebay.com/oauth/api_scope.

    A shortcut to get your code run: the refresh token is actually the token you have for standard API, which is valid for 18 months. With a refresh token, you can get token without getting the annoying "authorization code" via user consent.

    In short, please use refresh token to get user access token for the restful API.

    Hope the above helps.

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