Message form data with axia in Node.js

I am testing the Uber API on Postman and I can successfully send a request with form data. When I try to translate this request using Node.js and in the axios library, I get an error.

Here's what my Postman request looks like:

Postman post request

The answer I get is: { "error": "invalid_client" }

Here is what I do in Node.js and axios:

 var axios = require("axios"); const config = { headers: { 'Content-Type': 'multipart/form-data' } }; axios.post('https://login.uber.com/oauth/v2/token', { client_id: '***', client_secret: '***', grant_type: 'authorization_code', redirect_uri: 'http://localhost:8080/', code: '***' }, config) .then(function(response) { console.log(response.data) }) .catch(function(error) { console.log(error) }) 

When I do this, I get a 400 response.

I added the header 'multipart/form-data' because I filled in the form data in a Postman request. Without a header, I get the same result.

I expect to get the same answer I get from Postman, is there something wrong with my configuration variable in the Node.js script?

Any help would be appreciated!

+5
source share
2 answers

As of June 10, 2017, the axios library axios not support sending form form data to Node.js. Here is a question about GitHub - https://github.com/mzabriskie/axios/issues/789

We had a similar problem, and I decided to go to the request library.

+4
source

Due to the error, it seems your client_id or client_secret is incorrect. Enable debugging and share the raw request / response (after filtering credentials).

+1
source

Source: https://habr.com/ru/post/1263096/


All Articles