Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
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 answers
Answer question

0

Try destructuring it:

.then({data}) => {
    console.log(data.parameter1);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!