Information submitted through the support site is private but is not hosted within your secure CDD Vault. Please do not include sensitive intellectual property in your support requests.

R Scripting Language

 If you require the use of the scripting language R for your API programming, you will require the following package:

  • httr
install.packages("httr")

httr's content() can parse JSON information.  If you are more familiar with the jsonlite library, installed with:

install.packages("jsonlite")

you can replace:

content(response)

with:

jsonlite::fromJSON(content(response, as = 'text'))

in any of the examples below.

 

The examples below assume you have saved your api token as a variable in the session:

TOKEN='AAAAAAAAAAAAAAAAAAAAAAA='

 

Examples

A simple example of an API call with R would look like this:

library(httr)
response<-GET("https://app.collaborativedrug.com/api/v1/vaults", add_headers(.headers = c("X-CDD-Token"=TOKEN)))
stop_for_status(response)
content(response)
 

 

Another example using R, a POST request, can be written like this:

library(httr)
response<-POST("https://app.collaborativedrug.com/api/v1/vaults/1234/molecules", body='{"name": "empty", "projects": [938429932]}', add_headers(.headers = c("X-CDD-Token"=TOKEN)))
stop_for_status(response)
content(response) 

 

Another example using R, a POST request for Bulk Import, can be written like this:

library(httr)

# To run Bulk Import POST command
response<-POST("https://app.collaborativedrug.com/api/v1/vaults/1234/slurps", body = list(file = upload_file("C:/path/to/file/using/only/forward/slashes/filename.txt"), json = '{"project":"PROJECT-NAME"}'), add_headers(.headers = c("X-CDD-Token"=TOKEN)) ,verbose())
stop_for_status(response)

# To view the SLURP-ID
content(response)

# To Check Status of the Bulk Import POST command
checkresponse<-GET("https://app.collaborativedrug.com/api/v1/vaults/1234/slurps/SLURP-ID", add_headers(.headers = c("X-CDD-Token"=TOKEN)))
stop_for_status(checkresponse)

# To view JSON output of the Bulk Import POST command
content(checkresponse)