Wondering What I am doing wrong. I am trying to request a token in order to start using the APIs, inside of an Angular Application. I have been successful using the nodeJS SDK you have provided but wanted to figure out as an extra challenge how to do it on my own with Angular since I am not well versed in OAuth stuff. Obviously the Client Id and secret I use are different but wanted to avoid posting them here
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
data = "grant_type=client_credentials&client_id={1234567897}&client_secret={123456}"
getAmadeusAuthToken(): Observable<any> {
let headers = new HttpHeaders();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post('https://test.api.amadeus.com/v1/security/oauth2/token', this.data, this.httpOptions)
}
I have also tried to format the body different so:
data = {
grant_type: 'client_credentials',
client_id: '1234567897',
client_secret: '123456',
}
and also tried this:
data = "grant_type=client_credentials&client_id=1234567897&client_secret=123456"
but I always end up getting the same error which is:
code: 38187
error: "invalid_client"
error_description: "Client credentials are invalid"
title: "Invalid parameters"
message: "Http failure response for https://test.api.amadeus.com/v1/security/oauth2/token:
401 Unauthorized"
name: "HttpErrorResponse"
ok: false
status: 401
statusText: "Unauthorized"
url: "https://test.api.amadeus.com/v1/security/oauth2/token"
To make sure I was not putting in the wrong client ID or Secret I put the same one in the nodeJS SDK that you provide and it worked without any problems. Any sort of help would be appreciated. I am sure I am doing something wrong with the post request.
I ended up figuring it out after running it through an api tester. Angular HTTP is not very helpful IMO, anyhow for anyone that might have an issue in the future here is the solution, quick and dirty before needed refactoring:
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
dataString = "grant_type=client_credentials&client_id= 1234567897&client_secret= 123456"
getAmadeusAuthToken(): Observable<any> {
return this.http.post('https://test.api.amadeus.com/v1/security/oauth2/token', this.dataString, this.httpOptions)
}