Getting Analysis Results with the API

We can extract the analysis results via the REST API in two formats:

  • Tabular Result: The aggregated results are returned for a combination of dimensions.
  • Grouped Result: The aggregated results are returned for a value of the specified dimension.

Tabular result:

Here is an example of fetching a tabular result. Here, we are fetching the aggregates analyzed from 2012-12-1 to 2013-1-31.

curl -v -X GET \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Accept: application/vnd.kii.TabularAnalyticResult+json" \
  "https://api.kii.com/api/apps/{APP_ID}/analytics/{AGGREGATION_RULE_ID}/data?startDate=2012-12-1&endDate=2013-1-31"

You get the result with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.

Kii Cloud will return the result like the following.

{
  "labels" : [ {
    "label" : "Gender",
    "type" : "DIMENSION"
  }, {
    "label" : "City",
    "type" : "DIMENSION"
  }, {
    "label" : "Location",
    "type" : "DIMENSION"
  }, {
    "label" : "No. Of Children",
    "type" : "DIMENSION"
  }, {
    "label" : "Age",
    "type" : "DIMENSION"
  }, {
    "label" : "Count",
    "type" : "FACT"
  } ],
  "snapshots" : [ {
    "createdAt" : 1357862400000,
    "data" : [ [ "M", "San Francisco", "US", 1, 40, 1 ],  (...snip...)  , [ "F", "Tokyo", "JP", 2, 39, 2 ] ]
  }, {
    "createdAt" : 1357948800000,
    "data" : [ [ "F", "New York", "US", 3, 35, 2 ],  (...snip...)  , [ "F", "Kyoto", "JP", 0, 18, 1 ] ]

  (... snip ...)

  } ]
}

We can also specify some filters (e.g. only fetch the aggregates for "age"= 22). Please refer the detailed REST API documentation to learn more.

Grouped result:

Here is an example of fetching a grouped result. Here, we are fetching the aggregates analyzed from 2012-12-1 to 2013-1-31 while grouping the results with the dimension "location". (For specifying the dimension, use the value set as "Name" when you define your Aggregation Rule).

curl -v -X GET \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Accept: application/vnd.kii.GroupedAnalyticResult+json" \
  "https://api.kii.com/api/apps/{APP_ID}/analytics/{AGGREGATION_RULE_ID}/data?startDate=2012-12-1&endDate=2013-1-31&group=location"

You get the result with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.

Kii Cloud will return the result like the following.

{
  "snapshots" : [ {
    "name" : "New York",
    "data" : [ 10, 10, 11,  (...snip...)   , 12 ],
    "pointStart" : 1357862400000,
    "pointInterval" : 86400000
  }, {
    "name" : "Tokyo",
    "data" : [ 5, 8, 10,  (...snip...)   , 15],
    "pointStart" : 1357862400000,
    "pointInterval" : 86400000
 }, {

  (... snip ...)

  } ]
}

The response contains the following information:

  • name: The label of the dimension/grouping key (i.e., the value set as "Label" when you define your Aggregation Rule. If you did not set it, the value set as "Name" will be used instead).
  • data : The JSON Array that contains the data retrieved by the query.
  • pointStart : The date (milliseconds since UNIX epoch in UTC) in which the data starts.
  • pointInterval : Interval (in milliseconds) between data points.

We can also specify some filters (e.g. only fetch the aggregates for "age"= 22). Please refer the detailed REST API documentation to learn more.