skip to Main Content

I need help in understanding a problem of token when trying to get an offer’s information using https://api.ebay.com/sell/inventory/v1/offer/OFFER_ID endpoint.

I’ve got 2 types of tokens:
User token and Access token.

Documentation clearly gives me the explanation that I must use the USER TOKEN.
I made it using Auth’n’Auth method, I agreed to give permission as a seller. Now I am trying to use this token like that:

public void getOffer(@RequestBody Map<String, String> args) throws IOException {
    HttpClient client = HttpClientBuilder.create().build();
    HttpGet httpGet = new HttpGet("https://api.ebay.com/sell/inventory/v1/offer/OFFER_ID");

    httpGet.setHeader("Authorization", "Bearer " + args.get("token"));
    httpGet.setHeader("Content-Language", "en-US");

    HttpResponse response = client.execute(httpGet);
    System.out.print(EntityUtils.toString(response.getEntity()));
}

It keeps returning me:

{
  "errors" : [ {
    "errorId" : 1001,
    "domain" : "OAuth",
    "category" : "REQUEST",
    "message" : "Invalid access token",
    "longMessage" : "Invalid access token. Check the value of the Authorization HTTP request header."
  } ]
}

What can be wrong and what steps I missed?
Thank you in advance

2

Answers


  1. Well it’s giving you the exact error that is occurring:
    Invalid access token. Check the value of the Authorization HTTP request header.”

    That means you have an issue with this line of code…

    httpGet.setHeader("Authorization", "Bearer " + args.get("token"));
    

    Something is wrong with the Authorization header, so either the token is wrong, the value isn’t correct, or it’s just not receiving it. Is the word “Bearer” supposed to be send with the header? And does the value of the args.get(“token”) contain the correct value?

    Another issue that happens a lot with REST services, sometimes you have to use an HTML entities function to encode the strings/ldata you are attaching to a web request. Because you have a space in the authorization, perhaps the space isn’t interpreting correctly from eBay and you have to use HTML entities on the string. Something like this…

     httpGet.setHeader("Authorization", HttpUtility.HtmlEncode("Bearer " + args.get("token"));
    
    Login or Signup to reply.
  2. I made it using Auth’n’Auth method

    There are two versions of an User Token. eBay provides an older style called “Auth ‘n’ Auth” and a newer OAuth version. The “Auth ‘n’ Auth” token does not work with the new RESTFul APIs. You need to generate an OAuth User Token following the process found in the documentation.

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