Skip to content

Translating Curl Request with Form Data to Axios

I’m trying to mimic the following request using axios:

curl -i -k --tlsv1.2 -H "Accept:application/json" -H "Content-Type:application/x-www-form-urlencoded" -d "client_id=YOUR_CLIENT_ID" -d "client_secret=YOUR_CLIENT_SECRET" -d "grant_type=refresh_token" -d "refresh_token=REFRESH_TOKEN_FROM_ACCESS_TOKEN_RESPONSE" -X POST

More information:

I came up with the following code:

axios({method: ‘post’, url: ‘’, params: {client_id: ‘…’, client_secret: ‘…’, grant_type: ‘refresh_token’, refresh_token: ‘…’}, headers: {‘Content-Type’: ‘aplication/x-www-form-urlencoded’, Accept: ‘application/json’ }}).then(res => console.log(res)).catch(ex => console.log(ex))

This keeps timing out and not giving me any response, which leads me to believe my request is malformed. Am I doing something wrong in trying to create this request with form data using axios?


See the documentation:

params are the URL parameters to be sent with the request

To send data in the body use body, not params and pass it a URLSearchParams object, not a plain object.