GETTING STARTED

DataSpark Mobility Intelligence APIs gives insight into where, why and how people move across Singapore. Our APIs provide programmatic access to our rich mobility intelligence dataset. Easily integrate Mobility Intelligence into your existing applications and analytics tools through standards-based APIs.

Complete the steps in this article to get up and running, and to familiarise yourself with all of DataSpark’s APIs. Please note that using our APIs requires experience with programming.

If you are looking for our Australian APIs, please contact our Australian team for more information.

Step 1: Create a DataStreamX Account

Through DataStreamX, you are able to trial the APIs for free, no credit card details required. You will need to register an account on DataStreamX in order access our APIs.

 

Step 2: Subscribe to Mobility Intelligence API on DataStreamX 

After your DataStreamX account is set up, you can subscribe to our APIs for free. See our page on DataStreamX here.

 

Step 3: Get Your Access Token

After you have subscribed to an API, you will be assigned an API key (data key). The API key can be found by clicking the “Access Subscriptions” link on the top right corner of the page.

If you have multiple subscriptions, they will be listed in the drop-down list as shown in the preceding screenshot. Each subscription has a different API key.

Choose the appropriate subscription and then find the API key in the following sample screenshot. The screenshot is for illustration purpose only, hence the API key is blurred out. The API key would be required for authenticating the API.

Step 4: Send your first API request

Here is an example of querying our Discrete Visit API. Change the YOUR_DATASTREAMX_KEY to the key you received from step 3.

Code

curl -X POST --header 'Content-Type:
application/json' --header 'DataStreamX-Data-Key:YOUR_DATASTREAMX_KEY' -d
'{"date": "2017-05-30","location":
{"locationType": "locationHierarchyLevel", "levelType":"discrete_visit_subzone","id":
"OTSZ02"},"queryGranularity": {"type":
"period", "period":
"PT1H"},"aggregations": [{"metric":
"unique_agents", "type": "hyperUnique",
"describedAs": "footfall"}]}' 'http://api.datastreamx.com/1925/605/v1/discretevisit/v2/query'

Code

import json, ast

import requests

DataStreamXKey = "YOUR_DATASTREAMX_KEY"

queryBody = {"date":
"2017-05-30","location": {"locationType":
"locationHierarchyLevel",
"levelType":"discrete_visit_subzone","id":
"OTSZ02"},"queryGranularity": {"type":
"period", "period": "PT1H"},"aggregations":
[{"metric": "unique_agents", "type":
"hyperUnique", "describedAs": "footfall"}]}

queryResponse = requests.post("http://api.datastreamx.com/1925/605/v1/discretevisit/v2/query",
data = json.dumps(queryBody),headers = {'DataStreamX-Data-Key': DataStreamXKey,
'Content-Type': 'application/json'})

result = [ast.literal_eval(json.dumps(i)) for i in
queryResponse.json()]

print result

Code

library(httr)
library(dplyr)
library(jsonlite)

#parameters
datastreamx.key = "YOUR_DATASTREAMX_KEY"

#query API
query.body <- list(
  date = "2017-05-30",
  location = list(locationType = "locationHierarchyLevel", levelType = "discrete_visit_subzone", id = "OTSZ02"),
  queryGranularity = list(type = "period", period = "PT1H"),
  aggregations = list(list(metric = "unique_agents", type = "hyperUnique",
describedAs = "footfall"))
)

# token variable contains a valid access token; see Getting Started.
query.response <- POST("http://api.datastreamx.com/1925/605/v1/discretevisit/v2/query",
add_headers('DataStreamX-Data-Key' = datastreamx.key),
encode = "json",
body = query.body,
verbose())

stop_for_status(query.response)
cat(content(query.response, as = "text"), "\n")

#convert query response to JSON

data <- fromJSON(rawToChar(query.response$content))
data.df <- do.call(what = "cbind", args = lapply(data, as.data.frame))
names(data.df)[1] = names(data[1])

#write csv to working directory

write.csv(data.df, file = "API-output.csv")

Step 5: Learn more about each of our APIs

O-D MATRIX API

Get up-to-date information on Origin-Destination pairs across Singapore, for any time and any day.
Get Started

Stay point API

Discover where people are hanging out and spending time in.
Get Started

Discrete Visit API

For points of interest across Singapore, uncover how many people there are and who they are.
Get Started