Hi I have created two function, one for getting token the other one for getting recommended destination which requires the token from the first function but the getToken function kept returning undefined but when I console.log in the getToken() function I got the value but after passing this value into the getDestination() the value is undefined so I am unsure of what is the mistake here. Thank you.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="getDestination(getToken())"></button>
</body>
</html>
<script>
function getToken(){
var settings = {
"url": "https://test.api.amadeus.com/v1/security/oauth2/token",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "client_credentials",
"client_id": "IfOSPsTBNvRkU0ViJhpgMiUhW005PX7a",
"client_secret": "ATXw6AGIidOEJY7c"
}
};
$.ajax(settings).done(function (response) {
let token = response.access_token
console.log(token)
return token
});
}
function getDestination(token){
console.log(token)
var settings = {
"url": "https://test.api.amadeus.com/v1/reference-data/locations/pois?",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Bearer 38UWGbcuhGDD0Xu3swMvaUIDAELi"
},
data: {
'latitude' : 41.397158,
'longitude' : 2.160873,
'radius' : 2,
}
};
$.ajax(settings).done(function (response) {
console.log(response)
});
}
</script>