I'm working on an Ionic 2 Application, which use third-party API from Oxford Dictionary. Their API require app_id
and app_key
as authentication step to work.
Here is the service which make the GET
request call to the API
@Injectable()
export class OxfordVocabularyService {
private app_id: any;
private app_key: any;
private OxfordBaseRequestURL: any;
constructor(private http: Http) {
this.app_id = configuration.oxfordAPI.app_id;
this.app_key = configuration.oxfordAPI.app_key;
this.OxfordBaseRequestURL = configuration.oxfordAPI.requestURL;
}
public getWordIPA(word: String): Promise<any> {
let headers = new Headers({ 'Accept': 'application/json' });
headers.append('app_id', this.app_id);
headers.append('app_key', this.app_key);
let options = new RequestOptions({ headers: headers });
return this.http.get(this.OxfordBaseRequestURL + word + '/pronunciations', options).toPromise().then(response => {
console.log(response.json());
});
}
When the app run the service call, it throws err
The API request works perfectly fine on Postman
I have attached the app_id
and app_key
on headers request, so why do i get the error.
403 - Authentication Parameters missing
Is this something related to CORS ? Can you show me the way to make the API call properly ?
Update
Huge thanks to @suraj and @n00dl3, i have solved the problem by adding a proxy to the Ionic Configuration.
ionic.config.json
"proxies": [
{
"path": "/oxfordapi",
"proxyUrl": "https://od-api.oxforddictionaries.com/api/v1/entries/en"
}
]
And change the GET
request path to
this.http.get('oxfordapi/' + word + '/pronunciations', options)