imd imd - 2 months ago 12x
R Question

Connecting to BI tool's REST API using rcurl

I am trying to connect directly to a BI tool's API from within R. The API Documentation lists the curl command below to obtain an authentication token:

curl -X POST -H "Content-Type: application/json" -d
"email": "",
"password": "your_password"

Further, below is an example of a JSON query that can be used to query data:

"brandId": "9999",
"dateRange": "CUSTOM",
"startDate": "2016-01-01",
"endDate": "2016-12-31",
"measurements": [
"name": "Impressions"
"dimensions": [
"groupDimensionFilters": [],
"stringDimensionFilters": [],
"stringDimensionFiltersOperator": "AND",
"numberDimensionFiltersOperator": "AND",
"numberMeasurementFilter": [],
"sortBy": "Month",
"sortOrder": "DESC",
"topResults": "50",
"groupOthers": true,
"topPerDimension": true,
"totalDimensions": []

I'm trying to 1) translate the curl command above into R so as to obtain the authentication token required, and 2) query the data through the JSON script above.

So far i've attempted using the
library as follows:

r <- POST('',
body = list(
brandId = "9999",
dateRange = "CUSTOM",
measurements = list(name="Impressions"),
dimensions = list(name="Month"),
startDate = "2016-01-01",
endDate = "2016-12-31"
encode = "json",
authenticate("username", "password"))

to no avail.

The API documentation is behind a password protected page and as such i'm unable to link it. Let me know if additional information is required.


hrbrmstr is totally right! you should generate two api calls, the first one is to authenticate the user and the second one is to query the data.

Below is a fully working example of using the Datorama query API from R. feel free to contact the Datorama support for any additional questions.


res <- POST("",

token <- content(res)$token

res_query <- POST(paste("",token, sep=""),
        body = list(
              brandId = "9999",
              dateRange = "CUSTOM",
              measurements = list(list(name = "Impressions")),
              dimensions = list("Month"),
              startDate = "2016-01-01",
              endDate = "2016-12-31"
          encode = "json")

cat(content(res_query, "text"), "\n")