v1

latestOpenAPI 3.1.02026-07-2419603.1 MB
Analytics

Execute query

API that allows querying the database directly. Please note that each request must be authenticated.

Copy definition

You can use the View API call definition option available in Analytics module in each report to get more usage examples based on your existing reports.

View API call definition

Compression

When requesting large amount of data, make sure to include an Accept-Encoding: gzip header to enable compression.

Cache

Please note that all query results are cached for 10 minutes.

post/api/analytics/v1/query/

Request body

website_idstring uuid required

ID of a website or a meta site.

relative_date'today' | 'yesterday' | 'last_week' | 'last_month' | 'last_year' | 'last_X_days'

Use relative date in query. Cannot be used with absolute date fields at the same time. X in last_X_days must be in range 1 <= X <= 365. Note that last_X_days does not include data from today. Mandatory if absolute date fields are not used.

offsetinteger

Number of rows to skip before beginning to return rows.

limitinteger

Number of rows to return.

format'json' | 'json-kv' | 'csv' | 'xml'

Data format of a successful response (error responses are always in json).

column_format'id' | 'name'

Format of the columns header (in CSV responses) and metadata labels (in JSON responses). By default uses identifiers (id option), set to name to use human-readable names.

Example request

{
  "website_id": "70236925-724f-404e-b634-7b5633bc0bcc",
  "columns": [
    {
      "column_id": "device_type"
    },
    {
      "column_id": "revenue",
      "transformation_id": "sum"
    }
  ],
  "date_from": "2020-02-10",
  "date_to": "2020-02-10",
  "filters": {
    "operator": "and",
    "conditions": [
      {
        "column_id": "event_title",
        "condition": {
          "operator": "contains",
          "value": "test"
        }
      }
    ]
  },
  "metric_filters": {
    "operator": "and",
    "conditions": [
      {
        "column_id": "page_views",
        "condition": {
          "operator": "eq",
          "value": 42
        }
      }
    ]
  },
  "offset": 0,
  "limit": 100,
  "order_by": [
    [
      0,
      "desc"
    ],
    [
      1,
      "asc"
    ]
  ],
  "format": "json",
  "options": {
    "sampling": 0.2
  }
}

Response

OK

dataobject[]

Rows with results for the query.

Example response

{
  "data": [
    [
      [
        1,
        "Smartphone"
      ],
      0
    ],
    [
      [
        0,
        "Desktop"
      ],
      0
    ]
  ],
  "meta": {
    "columns": [
      "device_type",
      "revenue__sum"
    ],
    "scope": "event",
    "blended_datasets": [],
    "count": 2
  }
}