ebay-api icon indicating copy to clipboard operation
ebay-api copied to clipboard

get error Token not available in request. Please specify a valid token as HTTP header.

Open 123bistami opened this issue 1 year ago • 6 comments

my code

const eBay = new eBayApi({
        appId: 'XXXXXXXXXXXXXXXXXX',
        certId: 'XXXXXXXXXXXXXXXXXX',
        devId: 'XXXXXXXXXXXXXXXXXX',
        authToken: 'XXXXXXXXXXXXXXXXXX',
        siteId: eBayApi.SiteId.EBAY_DE,
        marketplaceId: eBayApi.MarketplaceId.EBAY_DE,
        sandbox: false
    });

(async () => {
        const result = await eBay.shopping.GetUserProfile({
            UserID: 'xxxxx',
            IncludeSelector: 'Details'
        });

        console.log(result);
    })()

response is

description: 'Token not available in request. Please specify a valid token as HTTP header.',
  meta: {
    Timestamp: '2022-08-14T12:08:53.414Z',
    Ack: 'Failure',
    Errors: {
      ShortMessage: 'Token not available in request.',
      LongMessage: 'Token not available in request. Please specify a valid token as HTTP header.',
      ErrorCode: 1.33,
      SeverityCode: 'Error',
      ErrorClassification: 'RequestError'
    },
    Build: 'E1199_CORE_APILW_19146596_R1',
    Version: 1199,
    [Symbol(raw-error)]: {
      Timestamp: '2022-08-14T12:08:53.414Z',
      Ack: 'Failure',
      Errors: {
        ShortMessage: 'Token not available in request.',
        LongMessage: 'Token not available in request. Please specify a valid token as HTTP header.',
        ErrorCode: 1.33,
        SeverityCode: 'Error',
        ErrorClassification: 'RequestError'
      },
      Build: 'E1199_CORE_APILW_19146596_R1',
      Version: 1199
    }
  }
}

i had inserted a static token, ebay API explorer call works fine, pls help!

123bistami avatar Aug 14 '22 12:08 123bistami

authToken is used for the traditional Auth'N'Auth method. I think you are looking for:

eBay.OAuth2.setCredentials('XXXXXXXXXXXXXXXXXX');
// This token can be seen in the eBay API explorer.

dantio avatar Aug 14 '22 13:08 dantio

what was the issue?

dantio avatar Aug 14 '22 15:08 dantio

If you are only using the traditional API, you can use the Auth'n'Auth Token. It is valid for 2 years. You can generate it on the eBay developer page where you define your Application Login etc. Put the token as in your first post.

Otherwise, you have to go through the Auth Flow once. You will receive an additional "refresh token". You can than refresh the access token if it's not valid anymore.

dantio avatar Aug 15 '22 08:08 dantio

Show me the whole code. Does it work with ebay api explorer? Did you managed to obtain the access token?

dantio avatar Aug 17 '22 16:08 dantio

You have to replace categoryId=9355 with categoryId:9355 in aspect_filter like this: https://api.ebay.com/buy/browse/v1/item_summary/search?category_ids=9355&limit=3&filter=sellers:{alba_mobil}&aspect_filter=categoryId:9355,Brand:{Apple},Model:{Apple iPhone 13 Pro}

await eBay.browse.search({
  "category_ids": "9355",
  "limit": 3,
  "filter": "sellers:{alba_mobil}",
  "aspect_filter": "categoryId:9355,Brand:{Apple},Model:{Apple iPhone 13 Pro}"
})

dantio avatar Aug 18 '22 10:08 dantio

Can you try with encoded aspect_filter? https://api.ebay.com/buy/browse/v1/item_summary/search?category_ids=139971&limit=3&filter=sellers:{saturn}&aspect_filter=categoryId%3A139971%2CBrand%3A%7BMicrosoft%7D%2CModel%3A%7BMicrosoft%20Xbox%20Series%20X%7D

Maybe you should ask in eBay Developer Forum...

dantio avatar Aug 21 '22 10:08 dantio

I think this might be related.

I'm calling "getMultipleItems" from the Shopping API:

eBayApi.shopping.GetMultipleItems.(fields, { useIaf: true });

When my OAuth2 token is expired, I get this error message:

EbayApiError: Invalid token.
  description: 'Invalid token. Please specify a valid token as HTTP header.',
  meta: {
    Timestamp: '2023-09-21T17:22:49.013Z',
    Ack: 'Failure',
    Errors: {
      ShortMessage: 'Invalid token.',
      LongMessage: 'Invalid token. Please specify a valid token as HTTP header.',
      ErrorCode: 1.32,
      SeverityCode: 'Error',
      ErrorClassification: 'RequestError'
    },
    Build: '1299_CORE_APILW_19146596_R1',
    Version: 1299,
    [Symbol(raw-error)]: {
      Timestamp: '2023-09-21T17:22:49.013Z',
      Ack: 'Failure',
      Errors: [Object],
      Build: '1299_CORE_APILW_19146596_R1',
      Version: 1299
    }
  }
}

And unfortunately, this isn't caught by the autoRefreshToken logic: https://github.com/hendt/ebay-api/blob/932d6878269ce3eae3a0457d2842ad9f293dc5b6/src/api/traditional/index.ts#L152

The above logic seems to correctly handle errors for the Trading API, but not the Shopping API.

nrathi avatar Sep 21 '23 17:09 nrathi

Thank you for reporting it and including the error message! I'll fix it soon.

dantio avatar Sep 21 '23 19:09 dantio

Can you re-open this ticket?

nrathi avatar Sep 26 '23 13:09 nrathi

Fix release in v8.5.1

dantio avatar Sep 28 '23 14:09 dantio