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

122
Views
Find a right way to convert cURL to a POST request axios

Hi guys just what the title says, I couldn't find a solution.

Here the cURl:

curl "https://test.api.amadeus.com/v1/security/oauth2/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}"

Here is my code that is getting a 400 error from server:

const getToken = async () => {
try {
  const res = await axios.post(
    "https://test.api.amadeus.com/v1/security/oauth2/token",
    null,
    {
      params: {
        client_id: process.env.REACT_APP_AMADEUS_API_KEY,
        client_secret: process.env.REACT_APP_AMADEUS_SECRET_API_KEY,
        grant_type: "client_credentials",
      },
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    }
  );
  console.log(res);
} catch (error) {
  console.log(error);
}};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

curl -d sends data as application/x-www-form-urlencoded body. params: config in axios.post sends data in query string. Use data: instead, or just specify the data in the second argument (replacing your null).

about 4 years ago · Juan Pablo Isaza Report

0

axios post method should have second parameter as body params and third parameter as config object like headers. below code might help you.

const getToken = async () => {
try {
  const res = await axios.post(
    "https://test.api.amadeus.com/v1/security/oauth2/token",
    {
        client_id: process.env.REACT_APP_AMADEUS_API_KEY,
        client_secret: process.env.REACT_APP_AMADEUS_SECRET_API_KEY,
        grant_type: "client_credentials",
      },
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    }
  );
  console.log(res);
} catch (error) {
  console.log(error);
}};
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!