Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

568
Vistas
axios returns 404 for a post request with form data

I am trying to get a graph token from Azure AD with a post request having form data through Axios. The response throws an error Request failed with status code 404. The below is the code,

const axios = require('axios')
const FormData = require('form-data')
    
const bodyFormData = new FormData()
    
bodyFormData.append('client_id', <client id>)
bodyFormData.append('client_secret', <secret>)
bodyFormData.append('scope', <scope>)
bodyFormData.append('requested_token_use', <token use>)
bodyFormData.append('assertion', <token>)
    
axios
.post('https://login.microsoftonline.com/<tenantId>/oauth2/v2.0/token', bodyFormData, {
headers: bodyFormData.getHeaders(),
})
.then((response) => {
console.log('AXIOS RESPONSE ', response)
})
.catch((err) => {
console.log('AXIOS ERROR ', err)
})

The post request works fine in the postman. The response in Axios is also as expected if bodyFormData is removed from Axios request. When bodyFormData is added to the request I encounter an error.

AXIOS ERROR Error: Request failed with status code 404

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Instead of using form-data use querystring

const axios = require('axios')
const querystring = require('querystring');

const data = querystring.stringify({
    client_id: '<client id>',
    client_secret: '<secret>',
    scope: '<scope>',
    requested_token_use: '<token use>',
    assertion: '<token>'
});

axios.post('https://login.microsoftonline.com/<tenantId>/oauth2/v2.0/token', data)
    .then((response) => {
        console.log('AXIOS RESPONSE ', response)
    })
    .catch((err) => {
        console.log('AXIOS ERROR ', err)
    });
over 4 years ago · Santiago Trujillo Denunciar

0

Try removing the headers part, it should work.

There should not be any reason having to get the headers from the FormData object, as it’s an API and will use other forms of authentication and could mess up the call.

It’s not a data scraping call that might be blocked by some security measure.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda