5

I'm trying to get access_token from a refresh token I got from eBay. I'm using Axios but I keep getting getting grant type in request is not supported error.

  const refreshToken = 'xxxxxxxx';
  const appID = 'xxxxxxx';
  const certID = 'xxxxxx';
  const scopes = [
        'https://api.ebay.com/oauth/api_scope',
        'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
        'https://api.ebay.com/oauth/api_scope/sell.account',
        'https://api.ebay.com/oauth/api_scope/sell.inventory'
  ]
  const params = {
    grant_type: 'refresh_token',
    refresh_token: refreshToken,
    'scope': encodeURI(scopes.join(" ")),
    // scope: scopes,
  

const token = Buffer.from(`${appID}:${certID}`);
const URL = 'https://api.ebay.com/identity/v1/oauth2/token'
const { data } = await axios.post(URL, params, {
      'headers': {
        'Authorization': `Basic ${token.toString('base64')}`,
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    })
Joe
  • 41,484
  • 20
  • 104
  • 125
ginad
  • 1,863
  • 2
  • 27
  • 42

1 Answers1

4

Turns out you'll have to UriEncode the entire request body, made use of node's querystring.encode():

const qs = require("querystring")
...
const { data } = await axios.post(URL, qs.encode(params), {
  'headers': {
    'Authorization': `Basic ${token.toString('base64')}`,
    'Content-Type': 'application/x-www-form-urlencoded',
  },
})
ginad
  • 1,863
  • 2
  • 27
  • 42