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);
}};
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).
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);
}};