API Key requirement

180 views
Skip to first unread message

Trish Whetzel

unread,
Jul 6, 2011, 12:34:59 PM7/6/11
to annotato...@googlegroups.com
Hi all,

As mentioned in previous emails on the NCBO Announce mailing list [1], the "apikey" parameter is now required for use of the NCBO Web services. In order to get your API Key, please login to BioPortal [2] and go to your Account page (drop-down menu item under your username in the upper right-hand corner). You will find your API Key at the bottom of this page. 

Trish


[1] https://mailman.stanford.edu/mailman/listinfo/bioportal-announce
[2] http://bioportal.bioontology.org/login

Taciana Gomes

unread,
Jul 14, 2011, 2:11:24 PM7/14/11
to annotato...@googlegroups.com
Hi all,

I am with a error when open this link: http://rest.bioontology.org/obs/ontologies
 <errorStatus>
<accessedResource>/obs/ontologies</accessedResource>
<accessDate>2011-07-14 11:07:08.725 PDT</accessDate>
<shortMessage>Forbidden</shortMessage>

<longMessage>
A valid API key is required to call REST services. Please visit http://bioportal.bioontology.org/account to get your API key.
</longMessage>
<errorCode>403</errorCode>
</errorStatus>

I have my api key, but i dont now what do.
please the only thing what i want is the number of nci-thesaurus.

thanks in advanced.
--
Taciana

Trish Whetzel

unread,
Jul 14, 2011, 2:18:34 PM7/14/11
to annotato...@googlegroups.com
Hi Taciana,

For the call to work, you'll need to append "?apikey=YourAPIKey". You can get your API Key by logging into BioPortal and then under your account name in the upper right-hand corner there is drop-down menu, click on "Account" and your API key is displayed on the resulting page. We've needed to add this parameter as a first step in providing access control for licensed ontologies.

Trish

Lauren

unread,
Mar 24, 2012, 1:24:27 AM3/24/12
to annotato...@googlegroups.com
Is this the case for other urls also? I was trying to access http://rest.bioontology.org/obs/annotator with httpClient to make queries but neither appending "?apikey=YourAPIKey" nor setting the parameter (by BasicHttpParams.setParameter("apikey", MY_KEY) and then HttpGet(annotatorurl).setParams(ALL_THE_PARAMETERS_I SET)) was allowing me to access the annotator. Appending the ?apikey=YourAPIKey" gave me a "no such methods error" and the latter gave me a "Forbidden-needs a valid Api key" error.

Any ideas on what my problem could be?

Thanks,
Lauren

Trish Whetzel

unread,
Mar 24, 2012, 2:11:04 AM3/24/12
to annotato...@googlegroups.com
Hi Lauren,

The API Key parameter should be passed into the Annotator web service call the same as the other annotator parameters. Here is a link to an example in the Perl sample code directory:
https://bmir-gforge.stanford.edu/gf/project/client_examples/scmsvn/?action=browse&path=%2Ftrunk%2FPerl%2FAnnotator-Perl%2Fannotator.pl&revision=29&view=markup

Trish


Trish Whetzel, PhD
Outreach Coordinator
The National Center for Biomedical Ontology
Ph: 650-721-2378
http://www.bioontology.org

"Like" NCBO on Facebook: http://on.fb.me/bioontology

Follow NCBO on Twitter: http://twitter.com/#!/bioontology

Join in Discussions on LinkedIn: http://linkd.in/ncbo-group

Lauren

unread,
Mar 24, 2012, 2:36:54 PM3/24/12
to annotato...@googlegroups.com
Thanks so much for your quick reply. I'm writing my code in scala so I tried to follow the java example. I tried setting the apikey parameter the way I set all the other ones, but it doesn't seem to work. I am able to access  http://rest.bioontology.org/obs/ontologies if I append ?apikey=MY_KEY but not by just setting the parameter.

Do you know why this is?

Trish Whetzel

unread,
Mar 24, 2012, 3:02:10 PM3/24/12
to annotato...@googlegroups.com
Can you send a snippet of the code where the parameters are specified? Also, are you making the annotator call as a POST call? The "obs/ontologies" call is a GET call.

Trish

Lauren

unread,
Mar 24, 2012, 5:57:06 PM3/24/12
to annotato...@googlegroups.com
I attached my code. I am making a GET call.

Thanks,
Lauren
controllers.scala

Trish Whetzel

unread,
Mar 25, 2012, 10:32:31 PM3/25/12
to annotato...@googlegroups.com
The Annotator call does need to be a POST call.

Trish

Lauren

unread,
Apr 3, 2012, 2:07:49 AM4/3/12
to annotato...@googlegroups.com
Okay, I changed to POST, but I'm still having trouble. I get the error "HTTP/1.1 403 Forbidden [Date: Tue, 03 Apr 2012 05:42:39 GMT, Server: Apache/2.2.13 (Red Hat), Content-Length: 401, Vary: Accept-Encoding, Connection: close, Content-Type: text/xml;charset=UTF-8]" with the message "A valid API key is required to call REST services." If I instead return 'method.getParams().getParameter("apikey").toString()' it will print the correct apikey, so that seems to be being set properly. Any idea what could be wrong? Here's what I have:

val annotatorUrl = "http://rest.bioontology.org/obs/annotator"

val client = new DefaultHttpClient()

var method = new HttpPost(annotatorUrl)

val params = new BasicHttpParams

params.setParameter("longestOnly", "true")
params.setParameter("wholeWordOnly", "true")
params.setParameter("filterNumber", "true")
params.setParameter("stopWords", "")
params.setParameter("withDefaultStopWords", "true")
params.setParameter("isTopWordsCaseSensitive", "false")
params.setParameter("mintermSize", "3")
params.setParameter("scored", "true")
params.setParameter("withSynonyms", "true")
params.setParameter("ontologiesToExpand", "")
params.setParameter("ontologiesToKeepInResult", "")
params.setParameter("isVirtualOntologyId", "true")
params.setParameter("semanticTypes", "")
params.setParameter("levelMax", "0")
params.setParameter("mappingTypes", "null")
params.setParameter("textToAnnotate", query)
params.setParameter("format", "xml")

params.setParameter("apikey", "MY_API_KEY")
method.setParams(params)

val response = client.execute(method)
return response.toString()
Thanks so much!

Lauren

unread,
Apr 5, 2012, 11:33:33 PM4/5/12
to annotato...@googlegroups.com
Never mind, I was able to solve it by:

var method = new HttpPost(annotatorUrl)
val params = new ArrayList[BasicNameValuePair]()
        
params.add(new BasicNameValuePair("apikey", apikey))
params.add(new BasicNameValuePair("textToAnnotate", query))
etc.

method.setEntity(new UrlEncodedFormEntity(params))

Still not sure why setParams didn't work.

Thanks so much for your help along the way!

Trish Whetzel

unread,
Apr 5, 2012, 11:46:30 PM4/5/12
to annotato...@googlegroups.com
Hi Lauren,

Glad to hear it's working now.

Trish
Reply all
Reply to author
Forward
0 new messages