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

132
Views
Unable to fetch response for login functionality
 const AUTH = () => {
    const params = JSON.stringify({
      user: {
        user_type: 'customer',
        mobile: '8349222680',
        password: '12345',
      },
    });
    const url = 'https://salon-host-dev.herokuapp.com/api/v1/logins/';
    axios
      .post(url, {
        headers: {
          'content-type': 'application/json',
        },
        body: JSON.stringify({
          data: 'data=' + JSON.stringify(params),
        }),
      })
      .then(response => {
        console.log('--->', response.status);
      });
  };

I am trying to get response from url but unable to that if Params passed in raw body json in postman then i am geeting expected response but not in following code please help

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The syntax for axios post request is below

axios.post(url, params, 
{headers: {'Content-Type':'application/json'}})
.then()

The header should be the 3rd argument to the POST method.

about 4 years ago · Juan Pablo Isaza Report

0

axios (and axios.post for that matter) can be called like axios.post(config) axios.post(url[, config]) axios.post(url[, data [, config]]) .... so you've chosen the second pattern,

the data to send is in data property, NOT the body property -

also you DONT need to send JSON, you can send the object

So given

const params = {
  user: {
    user_type: 'customer',
    mobile: '8349222680',
    password: '12345',
  },
};
const url = 'https://salon-host-dev.herokuapp.com/api/v1/logins/';

You can

axios.post({
  url: url,
  headers: {
    'content-type': 'application/json',
  },
  data: params,
})

or

axios.post(url, {
  headers: {
  'content-type': 'application/json',
  },
  data: params,
})

or

axios.post(url, params, {
  headers: {
    'content-type': 'application/json',
  }
})

Additionally, if you rename params to data

const data = {
  user: {
    user_type: 'customer',
    mobile: '8349222680',
    password: '12345',
  },
};

and create a headers variable

const headers = {
  'content-type': 'application/json',
};

you can do any of the following

axios.post(url, data, { headers });
axios.post(url, {data, headers});
axios.post({url, data, headers});
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!