0

All that I want to do at the moment is log the data that I'm trying to retrieve from the Sky Scanner API via a POST call but I'm getting error 500. Any ideas on what I'm doing wrong here?

Btw new programmer

Update: Error 400

const KEY = '123';

fetch("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0", {
 "method": "POST",
 "headers": {
  "x-rapidapi-host": "skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
  "x-rapidapi-key": `${KEY}`,
  "content-type": "application/x-www-form-urlencoded"
 },
 body: new URLSearchParams({
  "inboundDate": "2019-11-10",
  "cabinClass": "business",
  "children": "0",
  "infants": "0",
  "country": "US",
  "currency": "USD",
  "locale": "en-US",
  "originPlace": "SFO-sky",
  "destinationPlace": "LHR-sky",
  "outboundDate": "2019-11-20",
  "adults": "1"
   })
})
.then(response => {
 console.log(response);
})
.catch(err => {
 console.log(err);
});
Rob
  • 31
  • 4
  • A 500 error happens on the server-side. There _might_ be some hints in the response body text but that's pretty unlikely – Phil Nov 07 '19 at 00:43
  • From the linked duplicate, see [this answer](https://stackoverflow.com/a/53189376/283366) – Phil Nov 07 '19 at 00:48
  • Great! now I'm getting error 400: – Rob Nov 07 '19 at 01:03
  • 400 means _"bad request"_ so something in your data isn't valid for that service. Time to consult the API documentation if there is any – Phil Nov 07 '19 at 02:13

1 Answers1

0

You don't need to pass your API Key as a literal string.

Pass it something like this:

"x-rapidapi-key": KEY,

P.S. Use environmental variable to pass the API key as this is a sensitive credential.

Pratham
  • 497
  • 3
  • 7