Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios post, missing grant type

Tags:

axios

Getting data: { error: 'invalid_request', error_description: 'Missing grant type' } }

Content-Type is correct, not sure what is wrong

return axiosInstance({
  method: 'post',
  url: axiosInstance.defaults.baseURL + '/oauth/token',
  data: {
    "grant_type": "vapi_key",
    key: api_key
  },
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})

Edit: This is called via NodeJS

like image 794
FlyingSquirrel Avatar asked Jan 27 '23 02:01

FlyingSquirrel


1 Answers

This is an open issue about this matter. Try this solution, Which suggest stringifing the data (you can use qs package for it) :

import qs from 'qs';

return axiosInstance({
  method: 'post',
  url: axiosInstance.defaults.baseURL + '/oauth/token',
  data: {
    "grant_type": "vapi_key",
    key: api_key
  },
  data: qs.stringify({
    "grant_type": "vapi_key",
    key: api_key
  }),
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
like image 87
yuval.bl Avatar answered Feb 12 '23 09:02

yuval.bl