I am trying to request an authorization token from Amadeus using axios by following this documentation. However, I'm quite unexperienced with the axios library and am failing to build the request correctly, because I get this response:
code: 38187
error: "invalid_request"
error_description: "Mandatory grant_type form parameter missing"
title: "Invalid parameters"
The curious thing is that I tried to simulate the same request with curl and it worked, so I'm really puzzled as to where my error is. Below is my curl request
curl -v "https://test.api.amadeus.com/v1/security/oauth2/token"
-H "Content-Type: application/x-www-form-urlencoded"
-d "grant_type=client_credentials&client_id=xxxxxx&client_secret=xxxxxx"
Here is my JavaScript code, please let me know if you are able to notice the difference! Thanks in advance
async getAmadeusKey() {
const response = await axios({
url: "https://test.api.amadeus.com/v1/security/oauth2/token",
method: 'post',
headers: {
'Content-Type': 'x-www-form-urlencoded'
},
data: {
grant_type: 'client_credentials',
client_id: CLIENT_ID, // of course both these constants are defined outside of this scope
client_secret: CLIENT_SECRET,
}
});
console.log(response.data);
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/z6q7B29
Comments
Post a Comment