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

293
Vistas
Get value from axios response header

I'm calling an API which returns some data and aditional information. This information is located in a custom header. For that I have the following code:

const CallAPI = async param => {
    await axios.get("api url...")
    .then(response => {
        var headerValues = response.headers['x-customName'];
        /*This prints something like this: 
        {"Parameter1":633,"Parameter2":10}*/
        console.log(headerValues);
    });
}

What I'm trying to do is to get the value of any of those parameters. I tried doing something like this:

console.log(headerValues["Parameter1"]);
console.log(headerValues.Parameter1);

But with both I'm getting undefined result. I also tried converting my response header result to JSON and trying the above console.log using the following code, but I'm getting the same results.

JSON.stringify(response.headers['x-customName']);

What I'm doing wrong or what can I do to get those values?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try destructuring it:

.then({data}) => {
    console.log(data.parameter1);
}
about 4 years ago · Juan Pablo Isaza 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