Amadeus get token api error in JavaScript
Hello, I want to use the getToken Api provided by Amadeus using fetch in JavaScript in a React Native App. What I’am doing is the following:
`useEffect(() => {
const user_token_request = new
Request(urls.BASE_GENERATE_TOKEN_AMADEUS_URL, {
method: “POST”,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
},
body: JSON.stringify({
“client_id”: AMADEUS_CLIENT_ID,
“client_secret”: AMADEUS_CLIENT_SECRET,
“grant_type”: “client_credentials”
})
});
fetch(user_token_request)
.then((response) => response.json())
.then((data) => {
console.log("User Token: ", data);
})
.catch((error) => console.error(error));;
}, []);`
But I’m getting the following error:
{"code": 38187, "error": "invalid_request", "error_description": "Mandatory grant_type form parameter missing", "title": "Invalid parameters"}
, I know that the AMADEUS_CLIENT_ID, AMADEUS_CLIENT_SECRET and BASE_GENERATE_TOKEN_AMADEUS_URL has the correct value
I don’t understand why I’m getting this error since I passing "grant_type": "client_credentials"
Can anyone please enlighten me with this problem??
Randy Random is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.