ElsevierDev / apidemo

A Node.js program for use with api.elsevier.com. It demonstrates interoperability between the Scopus and SciVal APIs.
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

401 Error #1

Open Damahe88 opened 6 years ago

Damahe88 commented 6 years ago

Hi, Im having an issue with the api requests. It works fine when I use the implemented scopus search api: options.url = 'https://api.elsevier.com/content/search/scopus'; options.qs = { query: 'au-id(' + authorId + ')', field: 'eid,title,citedby-count,coverDate', sort: 'coverDate', count: 5 }

But when I change it to search for authors, I get an 401 AUTHORIZATION_ERROR: options.url = "https://api.elsevier.com/content/search/author": options.qs = { query: 'af-id(SOME-ID)', count: 25 }

Any suggestions? Thank you

yojoe26 commented 6 years ago

Hi,

I tried the code change and it seems to work OK for me. So it seems like it may be a permissions issue. Could you try and see if you have the same issue on the dev portal site for Scopus Author Search? If you get the same error there, you would need to contact the Scopus support team to determine why your account does not have access to the Author Search operation.

Thanks, Joe

Damahe88 commented 6 years ago

Hi Joe, thanks for your quick response. Yes I tried the API call in the dev Portal and it works fine. In general, the API calls over the browser seem to work fine. As soon as I take the query and use it with node I get the error. Could you maybe paste your implementation when calling the author search api? Generally, can I use the exact query string from the browser and paste it in a node application? Should that work? Or is some adjustment needed? Thanks

yojoe26 commented 6 years ago

Hi,

Sorry for the delay in responding. In general, yes, you should be able to use the exact same query string from the browser and past it into the node app. Here is an example of an author search using an affiliation ID as input:

https://api.elsevier.com/content/search/author?query=af-id(60025152)&apiKey=7f59af901d2d86f78a1fd60c1bf9426a

And here is the code snippet from server.js to make the same request:

    // Get the authors most recent pubs from Scopus
    options.url = 'https://api.elsevier.com/content/search/author';
    options.qs = {
        query: 'af-id(60025152)',
        count: 5
    }

Keep in mind that the node app will only work correctly if you create a config.js file that contains your API key and institution token (if defined) or use another type of authentication.

Thanks, Joe

Damahe88 commented 6 years ago

Hi, Joe thanks a lot. I will test it and give you feedback shortly

chokribr commented 3 years ago

@Damahe88 I think the problem is here https://github.com/ElsevierDev/apidemo/blob/master/server.js#L442 . If the api key is passed as head parameter the authentication will not work and you will get 401 error,strange but this the fact, we need to pass it as a query parameter.