Skip to content

query

POST /API/v2/query
Returns report data restricted by query parameters passed in POST arguments. See example.

Request body

  • slicer_name: the name of the report.
  • project_name: the name of the project.
  • token: the authorization token (see Authentication).
  • limit (optional): the maximum number of returned rows. Possible values: any integer in the range from -1 to 100,000. -1 means all rows. The default value is 100.
  • offset (optional): skip the specified number of rows from the result. Together with the limit POST argument allows querying large datasets. The default value is 0. Can be used only, if the limit POST argument is in the range from 0 to 100,000.
  • include_cumulative (optional): defines whether to display Total values for top N data rows, where N = limit + offset. Possible values: 0 - don't display Total values for top N data rows, 1 - display Total values for top N data rows. The default value is 0.
  • split_by: an array of the key fields to split data by in the form of ["key_field1",...].
  • include_mappings (optional): defines whether key field value mappings are returned by the API request. The default value is 1 (mappings are returned) if only 1 key field is used in the split_by POST argument. The default value is 0 (mappings are not returned) if 2 or more key fields are used in the split_by POST argument.
  • start_date, end_date: the start/end of the date range to gather data for. Supported formats:

    • Absolute dates: YYYY-MM-DD.
    • Relative dates:

      • today, yesterday
      • - N d and - N days for the number of days since the current date, where N - any positive integer or zero.
      • - N m and - N months for the number of months since the current date, where N - any positive integer or zero.
      • - N m_first, - N months_first- N m_last, and - N months_last for the first and the last day of the specified month correspondingly, where N - any positive integer or zero.
      • -N d_m_first, where N - any positive integer. The first day of the month matches the following date: current date + N days. Examples for the current date of 2021-10-12:


      Template Resulting start_date
      -15d_m_first 2021-09-01
      0d_m_first 2021-10-01
      15d_m_first 2021-10-01
      -100d_m_first 2021-07-01
      30d_m_first 2021-11-01
  • timezone (optional): time zone UTC offset in hours. Format: N, where N - any integer in the range of -12 <= N <= +12.

  • filters(optional): an array with the following structure:

    • "name": "key_field",
    • "case_insensitive": (optional), defines whether search should be case-insensitive. Possible values: (1 - case-insensitive, 0 - case-sensitive). The default value is 0.
    • "search_mappings": (optional), defines whether the search should be performed in mappings. Possible values: (1 - search should be performed in both key field values and their mappings, 0 - search should be performed in key field values only). The default value is 0.
    • "value": ["value1", ... ],
    • "match": "equals|not equals|contains|not contains|beginswith|endswith|not beginswith|not endswith"

    where the value of the "value" field should be an array.

    If "search_mappings" is set to 1, the search will be performed for both specified key field values and their mappings (descriptions). For example, if you have the creative_id key field with some value of "1" and its mapping of "First Creative", you can search for it as follows:

    {"name": "creative_id", "value": ["First Creative"],"match":"equals", "search_mappings": 1}

    OR

    {"name": "creative_id", "value": [1],"match": "equals"}

    Search results will be fully identical.

    You can even use a partial matching, like {"name":"creative_id","value": ["Creative"],"match":" contains", "search_mappings": 1}, but please note that if you use a too short search string (1 - 2 characters long), it may take significant time to look up all matching records.

  • data_filters(optional): an array with the following structure:

    • "name": "data_field",
    • "value": "value1",
    • "match": "<|>|<=|>=”

    where the "value" field is just one value. The "match" can be "<" for less than value, ">" for greater than value, "<=" for less than or equal to value, or ">=" for greater than or equal to value.

    If a data_field is in percent format, its value should also be divided by one hundred (30% becomes 0.3). Note, that this behavior is different in API and UI.

  • filter_template (optional): a string template defining priorities for filters specified in the filters POST argument. Can contain the following elements:

    • opening/closing parentheses
    • OR/AND operators
    • "x" character as a placeholder for filters

    Example: "x OR (x AND x)".

    Filters from the filters POST argument in the specified order are substituted instead of x.

  • data_filter_template (optional):a string template defining priorities for filtersspecified in the data_filters POST argument. Can contain the following elements:

    • opening/closing parentheses
    • OR/AND operators
    • "x" character as a placeholder for filters

    Example: "x OR (x AND x)".

    Filters from the data_filters POST argument in the specified order are substituted instead of x.

  • order_by  (optional): defines sorting rules. A single record or an array of records with the following structure:

    • "name": "field", the name of the key or data field to sort the results by. Note that this field can be any key field, specified in the split_by POST argument, or one of the data fields specified by the data_fields POST argument (or any of the data fields if the data_fields POST argument is not specified). The default value is the first column with enabled percent.
    • "mapping": defines whether to sort by key field ID or by key field mapping. Possible values: (0 - sort by key field ID, 1 - sort by key field mapping). The default value is 0.
    • "direction": sort in the ascending or descending order, either ASC or DESC. The default value is DESC.
  • data_fields (optional):  the array of data fields to be returned in the form of [ "data_field1", .... ]. If it is not defined (by default), data fields will not be returned. To receive the details of all data fields available for your particular report use the info method.

  • include_others (optional): return the summary of data outside the specified limit.

Response

  • status: the status of the request. success, if the request was processed successfully, or error code, if any error occurred. If the status is not success**, then the response contains the status and reason fields only. Possible values:
    • success: the request was processed successfully.
    • bad_request: invalid request parameters, please see the reason field for more details.
    • timeout: the request took too long to complete.
    • access_error: the user doesn't have access to the specified project/slicer, or a wrong token was used.
    • internal_error: the request failed due to an unknown problem.
  • reason: user-friendly description of the occurred error. This field is displayed for failed requests only.

  • total: this section contains information about the entire dataset returned by the query.

    • data: the summary values for each data column found in the result dataset. It's an array of elements with the following fields:
      • name: data field name.
      • value: data field value.
      • comment (optional): calculation comment (only for custom data columns), can be inf-inf in case of stack overflow, "Division by zero", and ERROR! at any other errors in calculation. In all of these cases, the value is displayed as 0.
    • records_found: the total number of found records.
    • confidence_range: the confidence range for data (in percent) in this section, if the returned dataset is compressed. Available for the Total rows. Contains “N/A” if compressed is unknown and 0 for uncompressed rows.
    • dates: the array with all the dates, for which data exist in the period from the start_date to the end_date.
  • cumulative (optional): this section contains Total values for top N data rows, where N = limit + offset, if the include_cumulative POST argument was set to 1.
    • data: the list of Total values matching top N data rows for the data fields specified in the data_fields POST argument. It's an array of elements with the following fields:
    • name: data field name.
    • value: data field Total value for top N data rows.
    • percent (optional): percent of the data field Total value for top N data rows (if applicable).
    • confidence_range: the confidence range for data (in percent) in this section, if the returned dataset is compressed. Available for the Total values matching top N data rows. Contains “N/A” if compressed is unknown and 0 for uncompressed rows.
    • key_count: the number of top N data rows, where N = limit + offset if the include_cumulative POST argument was set to 1.
  • rows: this section contains query data results. It is an array of data rows, each containing the following fields:

    • data: the list of items with the following field names and values:

    • name:data field name.

    • value: data field value.
    • percent (optional): percent of the total value (if applicable).
    • comment(optional): calculation comment (only for custom data columns), can be inf-inf in case of stack overflow, Division by zero", and ERROR! at any other errors in calculation. In all of these cases, the value is displayed as 0.
    • name: the value of the split_by key field for this row, including six specific time-related fields:
    • granularity_hour: data, aggregated by day+hour, where each key field value contains 1 item (date and hour) like:
      • "name": [ "2013-09-30 19:00" ]
    • granularity_day: data, aggregated by day, where each key field value contains 1 item (date) like:
      • "name": "2013-09-30"
    • granularity_week: data, aggregated by week, where each key field value contains 1 item (week) like:
      • "name" : "2013-W48"
    • granularity_month: data aggregated by month, where each key field value contains 1 item (month) like:
      • "name": "2013-09"
    • granularity_quarter: data aggregated by quarter, where each key field value contains 1 item (quarter) like:
      • "name": "2013 Q4"
    • granularity_year: data aggregated by year, where each key field value contains 1 item (year) like:
      • "name": "2013"

Note 1: If the split_by POST argument contains several key fields, then the name parameter also contains several key fields.

  • mapping (optional): the mappings of the current row key field values for the key fields specified in the split_by POST argument. Mapping display is defined by the include_mappings POST argument.

  • confidence_range: the confidence range for data (percent) in this section, if the returned dataset is compressed. Available for every data row in the resulting dataset.

  • percent (optional): percent of the data field Total value for data rows beyond the range defined by limit + offset (if applicable).

  • confidence_range: the confidence range for data (in percent) in this section, if the returned dataset is compressed. Available for the Total values matching data rows beyond the range defined by limit + offset. Contains “N/A” if compressed is unknown and 0 for uncompressed rows.

  • key_count: the number of data rows beyond the range defined by limit + offset.

  • others(optional): the summary of data rows beyond the range defined by limit + offset, if the include_others POST argument was set to 1. It's an array of elements with the following fields:

  • data: the list of Total values of data rows beyond the range defined by limit + offset for the data fields specified in the data_fields POST argument. It's an array of elements with the following fields:
    • name: data field name.
    • value: data field Total value for data rows beyond the range defined by limit + offset.

Example

Generate a Report on all Campaigns, containing the "100" string, displayed in California and Texas to users of the Opera internet browser for the period from March 01, 2012 to March 03, 2012, and show the following data fields only:

  • imps
  • clicks
  • pub_payout
  • ecpm

Path:

https://uslicer.iponweb.com/API/v2/query

Request

{
  "slicer_name": "Traffic Demo",
  "project_name": "demo",
  "token": "<token>",
  "split_by" : "campaign_id",
  "start_date" : "2012-03-01",
  "end_date" : "2012-03-03",
  "filters" : [
    {
      "name" : "geo_region",
      "value" : [
        "California",
        "Texas"
      ],
      "match" : "equals",
      "search_mappings": 1
      },
      {
        "name" : "campaign_id",
        "values" : [
          "100"
        ],
        "match" : "contains"
      },
      {
        "name" : "browser",
        "value" : [
          "Opera"
        ],
        "match" : "equals"
      }
  ],
  "data_fields" : [
    "imps",
    "clicks",
    "pub_payout",
    "ecpm"
  ]
}
curl --data '{
  "slicer_name": "Traffic Demo",
  "project_name": "demo",
  "token": "<token>",
  "split_by": "campaign_id",
  "start_date": "2012-03-01",
  "end_date": "2012-03-03",
  "filters": [
    {
      "name": "geo_region",
      "value" :[
        "California",
        "Texas"
      ], 
      "match": "equals", 
      "search_mappings": 1
    },
    {
      "name": "campaign_id",
      "value" :[
        "100"
      ],
      "match": "contains"
    },
    {
      "name": "browser",
      "value" :[
        "Opera"
      ],
      "match": "equals"
    }
  ], 
  "data_fields" :[
    "imps",
    "clicks",
    "pub_payout",
    "ecpm"
  ]
  }' \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  "https://uslicer.iponweb.com/API/v2/query"

Response

{
  "status" : "success",
  "rows" : [
    {
      "mapping" : null,
      "name" : "10065",
      "data" : [
        {
          "value" : 1018,
          "percent" : "50.88339",
          "name" : "imps"
        },
        {
          "value" : 1,
          "percent" : "100.00000",
          "name" : "clicks"
        },
        {
          "value" : 0.29,
          "percent" : "30.36148",
          "name" : "pub_payout"
        },
        {
          "value" : 0.29,
          "percent" : null,
          "name" : "ecpm"
        }
      ],
      "confidence_range" : "N/A"
    },
    {
      "mapping" : null,
      "name" : "10072",
      "data" : [
        {
          "value" : 951,
          "percent" : "47.52650",
          "name" : "imps"
        },
        {
          "value" : 0,
          "percent" : "0.00000",
          "name" : "clicks"
        },
        {
          "value" : 0.57,
          "percent" : "59.11783",
          "name" : "pub_payout"
        },
        {
          "value" : 0.604,
          "percent" : null,
          "name" : "ecpm"
        }
      ],
      "confidence_range" : "N/A"
    },
    {
      "mapping" : null,
      "name" : "10056",
      "data" : [
        {
          "value" : 32,
          "percent" : "1.59011",
          "name" : "imps"
        },
        {
          "value" : 0,
          "percent" : "0.00000",
          "name" : "clicks"
        },
        {
          "value" : 0.1,
          "percent" : "10.52068",
          "name" : "pub_payout"
        },
        {
          "value" : 3.211,
          "percent" : null,
          "name" : "ecpm"
        }
      ],
      "confidence_range" : "N/A"
    }
  ],
  "total" : {
    "dates" : [
      "2012-03-01",
      "2012-03-02",
      "2012-03-03"
    ],
    "data" : [
      {
        "value" : 2000,
        "name" : "imps"
      },
      {
          "value" : 1,
          "name" : "clicks"
      },
      {
          "value" : 0.97,
          "name" : "pub_payout"
      },
      {
          "value" : 0.485,
          "name" : "ecpm"
      }
    ],
    "records_found" : 3,
    "confidence_range" : "N/A"
  }
}

If no data exists for the specified combination of keys, values and match types, the response is as follows:

Response

{
  "status" : "success",
  "rows" : [],
  "total" : {
      "dates" : [
        "2012-03-01",
        "2012-03-02",
        "2012-03-03"
      ],
      "data" : [
        {
            "value" : 0,
            "name" : "imps"
        },
        {
            "value" : 0,
            "name" : "clicks"
        },
        {
            "value" : 0,
            "name" : "pub_payout"
        },
        {
            "value" : 0,
            "name" : "ecpm"
        }
      ],
      "records_found" : 0,
      "confidence_range" : "N/A"
  }
}

If you specify a wrong slicer name, the following error message is displayed:

Response

{
  "status" : "access_error",
  "reason" : "Wrong slicer name or slicer is unavailable"
}