0

I am trying to use SkyScanner API from Rapidapi with Angular to search for flight prices. here is my code

 headers = new Headers();
    url:string;
    
constructor(private _http:HttpClient,) {
this.headers.append('X-RapidAPI-Key', 'MY-KEY');
this.url = 'https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browseroutes/v1.0/IE/EUR/en-GB/{here should be other parameters like destination}' }

I am passing from,to,day,month and year from inputs

getFlightDetail(from,to,day,month,year) : Observable<Iflight>{
  return this._http.get<Iflight>(this.url+this.headers)
  .pipe(
    tap(data => console.log('flightData/error' + JSON.stringify(data))
    ),
    catchError(this.handlerError)
  );
}

the issue is when I ran the app I got

401 Unauthorized

1
  • Hi Omar, welcome to stackoverflow! You should double check how you are setting your http headers in your get call. It looks like you are adding them (string concatenation) to your url. Check out this link and see if it helps you out:stackoverflow.com/questions/42352854/… Commented Apr 22, 2021 at 1:17

1 Answer 1

0

x-rapidapi-host header is missing. You also need to add two custom headers if you're using RapidAPI, x-rapidapi-key and x-rapidapi-host

Also, I'm assuming you're already subscribed to Skyscanner API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.