brandonyrigan / jaunt

A travel planner for small excursions
https://brandonyrigan.github.io/jaunt/
1 stars 0 forks source link

Create Hotel Component #26

Open brandonyrigan opened 1 year ago

brandonyrigan commented 1 year ago
Henrymelendez commented 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();

Henrymelendez commented 1 year ago

where it came from :

https://stackoverflow.com/questions/65191717/authenticating-amadeus-test-flight-api-with-javascript-fetch

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();