Make your first API call

 

Basic example

You can find in this table the explanation of the main parameters. If you want more information, you can find them in the corresponding articles in the documentation in the category Parameters.
 
PARAMETERREQUIREDDESCRIPTION
spacetrueAnalysis scope (single site or multi-sites).
columnstrueList of properties & metrics to query (separated by a comma).
periodtrueAnalysis period (single, multiple, relative).
filterfalseFilters to be applied on properties/metrics.
evofalseTo obtain the evolution of a group of metrics over a certain time period.
sorttrueList of properties / metrics according to which the results will be sorted.
max-resultstrueNumber of results in the results page.
page-numtruePage number of the data set.
 

Parameter syntax

PARAMETERSYNTAX
space“space”: { “s”:[547656] }
columns“columns”: [ “visit_device_type”, “m_visits” ]
period“period”: { “p1”: [ { “type”: “D”, “start”: “2019-10-20”, “end”: “2019-10-24” } ] }
filter“filter”: { “metric”: { “m_visits”: { “$eq”: 19 } }, }
evo“evo”: { “granularity”: “D”, “top”: { “max-results”: 5, “page-num”: 1, “sort”: [“-m_visits”] } }
sort-by“sort”: [ “m_visits” ]
max-results“max-results”: 50
page-num“page-num”: 1
 
You can find below few complete examples to see how it could work.
 

var data = JSON.stringify({
"columns": [
"device_type",
"m_visits",
"m_users"
],
"sort": [
"-m_visits"
],
"space": {
"s": [429023]
},
"period": {
"p1": [
{
"type": "D",
"start": "2019-10-24",
"end": "2019-10-24"
}
]
},
"max-results": 50,
"page-num": 1
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.atinternet.io/v3/data/getData");
xhr.setRequestHeader("x-api-key", "YOURAPIKEY");
xhr.send(data); 

curl -X POST \
https://api.atinternet.io/v3/data/getData \
-H 'x-api-key: YOURAPIKEY' \
-H 'Content-Type: application/json' \
-d '{
"columns": [
"device_type",
"m_visits",
"m_users"
],
"sort": [
"-m_visits"
],
"space": {
"s": [429023]
},
"period": {
"p1": [
{
"type": "D",
"start": "2019-10-24",
"end": "2019-10-24"
}
]
},
"max-results": 50,
"page-num": 1
}'

import http.client
conn = http.client.HTTPSConnection("api.atinternet.io")
payload = '''{
"columns": [
"device_type",
"m_visits",
"m_users"
],
"sort": [
"-m_visits"
],
"space": {
"s": [547656]
},
"period": {
"p1": [
{
"type": "D",
"start": "2019-10-24",
"end": "2019-10-24"
}
]
},
"max-results": 50,
"page-num": 1
}
'''
headers = {
'x-api-key': "YOURAPIKEY",
'Content-type': "application/json"
}
conn.request("POST", "/v3/data/getData", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

request["x-api-key"] = 'YOURAPIKEY'
request.body = "{\n \"columns\": [\n \"device_type\",\n \"m_visits\",\n \"m_users\"\n ],\n \"sort\": [\n \"-m_visits\"\n ],\n\"space\": {\n \"s\": [\n 429023\n ]\n },\n \"period\": {\n \"p1\": [\n {\n \"type\": \"D\",\n \"start\": \"2019-10-24\",\n \"end\": \"2019-10-24\"\n }\n ]\n },\n \"max-results\": 50,\n \"page-num\": 1\n}"
response = http.request(request)
puts response.read_body

 

 

Output format

This Reporting API v3 allows you to get a response either in csv or in json, the default format being json:

  • JSON output: https://api.atinternet.io/v3/data/getData or https://api.atinternet.io/v3/data/json/getData
  • CSV output: https://api.atinternet.io/v3/data/csv/getData
 

POST or GET method?

The Reporting API v3.0 is designed to be used with the POST method. As you may have noticed, the content of the API call is getting longer and longer as all the fields are well described, and the GET method can be limited because of th length of the http request.

Last update: 04/05/2021