-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_example_calls.R
33 lines (24 loc) · 1.28 KB
/
api_example_calls.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# CURL example to get API results from OpenStudyBuilder
#
# Remark - you can get the current bearer token by executing by calling the API from the browser and copy the token
# goto - https://openstudybuilder.northeurope.cloudapp.azure.com/api/docs#/Studies/get_all_studies_get
# click "authorize" top right lock symbol, then "authorize"
# click "try it out"
# remove everything from the "filters" field
# click "execute"
# copy the bearer token from the CURL command (long string after "-H 'Authorization: Bearer ")
#
# setup for sandbox environment
api_url <- "https://openstudybuilder.northeurope.cloudapp.azure.com/api"
api_bearer <- "eyJ0eXA..." # enter your token here
library(httr)
response <- GET(paste(api_url,"studies", sep = "/"), add_headers(Authorization = paste("Bearer", api_bearer)))
studies <- jsonlite::fromJSON(rawToChar(response$content))
#str(studies)
#print(studies)
#print(studies[][["items"]][["uid"]])
#print(studies[][["items"]][["study_id"]])
cat(studies[][["items"]][["uid"]], studies[][["items"]][["study_id"]])
response <- GET(paste(api_url,"ct/terms?codelist_name=Sex", sep = "/"), add_headers(Authorization = paste("Bearer", api_bearer)))
ct_sex <- jsonlite::fromJSON(rawToChar(response$content))
print(ct_sex[["items"]][["name"]][["sponsor_preferred_name"]])