enricoferrero
enricoferrero

Reputation: 2319

How do I request an API token with httr?

I'm using httr to query the Open Targets API.

I received my API credentials (app_name and secret) and I'm now trying to request a token by attempting to translate the provided instructions for Python:

import requests  
API='https://www.targetvalidation.org/api/latest/'

jwt = requests.get(API + 'public/auth/request_token',  
                     params={'app_name':<appname>,'secret':<secret>})

print(jwt.json())  

Here's what I tried with R and httr:

library(httr)
app_name <- "myappname"
secret <- "mysecret"
token <-
 GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", app_name = app_name, secret = secret)
token <- GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", add_headers(app_name = app_name, secret = secret))
token <- GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", config = list(app_name = app_name, secret = secret))

# In all cases, this is what I get
token
# Response [https://www.targetvalidation.org/api/latest/public/auth/request_token]
#  Date: 2017-04-24 08:24
#  Status: 400
#  Content-Type: application/json
#  Size: 60 B
# {"message": {"app_name": "app name [appname] is required"}}

What is the right httr syntax to request this token?

Thanks!

Upvotes: 0

Views: 1216

Answers (1)

ep82
ep82

Reputation: 36

You have to pass the parameters as query, as explained in the httr quickstart:

token <- 
GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", 
 query=list(app_name = app_name, secret = secret)
)

Upvotes: 2

Related Questions