Open brandonyrigan opened 1 year ago
TRY THIS
const data = new URLSearchParams({ grant_type: 'client_credentials', client_id: CLIENT_ID, client_secret: CLIENT_SECRET });
const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: data });
const responseData = await response.json();
where it came from :
function getPlane(){ let url = "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=SYD&destinationLocationCode=BKK&departureDate=2021-02-01&returnDate=2021-02-05&adults=1&max=3"; fetch(url,{ method:"GET", headers:{ "Authorization": "Bearer ACCESS_TOKEN_HERE", }, mode:"cors", catch:"default" }).then(function(response){ if(response.ok){ return response.json(); }else{ throw new Error(error); } }).then(function(data){ console.log(data); //query data here document.getElementById("flight").insertAdjacentHTML('afterbegin',data.data[0].itineraries[0].segments[0].operating.carrierCode) }).catch(function(error){ console.log(error); }); }
getPlane();