Search code examples
httpresponseangular6scopus

angular6 - I can't get response from Scopus API


I want to use the Scopus API to verify that a DOI exists. I'm using the "Cited By" option. I did a test of this "http://api.elsevier.com/content/search/scopus?query=DOI(10.1016/j.stem.2011.10.002)" link in POSTMAN and it works, but when I did the implementation in Angular this is what returns.

Angular code

let headers = new Headers({ 
            'X-ELS-APIKey': apikey,
            'Accept': 'application/json',
        });
        this._http.get('http://api.elsevier.com/content/search/scopus?query=DOI(' + doi + ')', { headers: headers }).pipe(map(res => res.json())).subscribe(
            response => {
                console.log("Response");
                console.log(response);
            },
            error => {
                console.log("Error");
                console.log(error);
            }
        );

Any help is greatly appreciated :)


Solution

  • Finally I solved it, the problem was that the "doi" string needed to go through the encodeURIComponent() function. I leave the code in case someone needs it.

    welcome.component.ts:

    let doi = encodeURIComponent('10.1017/j.stem.2011.10.002');
    this._scopusService.getPublication(doi).subscribe(
        response => {
        console.log("DOI exists");
    },
    error => {
        console.log("DOI doesn't exists");
    }
    

    scopus.service.ts:

    public getPublication(doi) {
        let headers = new Headers({
            'Accept': 'application/json',
            'X-ELS-APIKey': this.apiKey
        });
    
        return this._http.get('https://api.elsevier.com/content/search/scopus?query=DOI(' + doi + ')', { headers: headers }).pipe(map(res => res.json()));
    }