I am trying to write simple mobile app in Ionic3 that will display fornite/pubg stats for the user. I am aware that there are multiple apps with same functionality out there, but I am doing that just to get a hang on ionic.
API provider has only one requirement on their page:
To make use of our APIs we require you to use an API Key. To use the API key you need to pass it along as a header with your requests. TRN-Api-Key: xxx-xxx-xxx
So, I wrote:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map';
@Injectable()
export class StatsProvider {
apiKey = 'xxx-xxx-xxx';
apiUrl ='https://api.fortnitetracker.com/v1/profile/pc/emulgator_';
constructor(public http: HttpClient) {
console.log('Hello StatsProvider Provider');
}
getStats() {
let headers = new HttpHeaders()
headers = headers.set('TRN-Api-Key', this.apiKey)
return this.http.get(this.apiUrl, {headers: headers}).map((res: Response) => res.json())
}
}
After, I subscribe to that:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { StatsProvider } from '../../providers/stats/stats';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
stats: any;
constructor(public navCtrl: NavController, private statsProvider: StatsProvider) {
}
ionViewWillEnter(){
this.statsProvider.getStats().subscribe(stats => {
console.log(stats);
});
}
}
But instead of response, I get bunch of errors in browser console:
https://api.fortnitetracker.com/v1/profile/pc/emulgator_ 404 ()
Failed to load https://api.fortnitetracker.com/v1/profile/pc/emulgator_: Response for preflight has invalid HTTP status code 404.
core.js:1350
ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
What I am doing wrong?