I am trying to interact with the NCBO annotator by setting a few parameters, then executing the request. However, the query returns an error: “Forbidden: A valid API key is required to call REST services. Please visit http://bioportal.bioontology.org/account to get your API key.”
My scala code is as follows:
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()
That returns “HTTP/1.1 403 Forbidden [Date: Mon, 02 Apr 2012 21:41:13 GMT, Server: Apache/2.2.13 (Red Hat), Content-Length: 401, Vary: Accept-Encoding, Connection: close, Content-Type: text/xml;charset=UTF-8]”
If I run the line:
return method.getParams().getParameter("apikey").toString()
it returns my correct api key, so it seems that that is being set correctly.
Any ideas as to what I am doing incorrectly?
Thanks.
I was able to solve it by:
Still not sure why setParams didn’t work.