Query
  • 20 Dec 2022
  • 2 Minutes to read
  • Dark
    Light

Query

  • Dark
    Light

Article Summary

Query

Query Report Data

POST /reporting/query

  • Request Parameters:

NameTypeInRequiredDescription
datasetIdstringbodyyesId of the dataset which need to query report.
filtersFilter[]bodyyesWhich filter conditions should be applied to the dataset when calculating the results of the metric. When there are multiple filters, the relationship between multiple filters is AND.
groupBysGroupBy[]bodyyesWhich groups should be applied to the dataset.
metricsMetric[]bodyyesWhich metrics should be calculated and displayed in the results.
timeZonestringbodyyesWhen time-related fields are needed to calculate report results, which time zone is used to calculate time. Available items includes all Time Zone Option.
  • Query Filter JSON Format

Filter is represented as simple flat JSON objects with the following keys:

NameTypeDescription
attributeIdstringThe id of the attribute which should be applied to the dataset.
filterValuesstring[]Values of the attribute which should be applied to the dataset. When there are multiple values, the relationship between the multiple values is OR. When attribute type is datetime, the first value is the start time, and the second value is the end time.
  • Query GroupBy JSON Format

GroupBy is represented as simple flat JSON objects with the following keys:

NameTypeDescription
attributeIdstringThe id of the dataset attribute which used to group in the report.
namestringThe name of the GroupBy. This will be used as the field name of the result.
timeDisplayTypestringAvailable when attribute is the type of datetime only. Available items are: day, week, month, quarter, year, hourOfDay, dayOfWeek, dayOfMonth, monthOfYear, quarterOfYear. The result set will have different values for this field.
  • Query Metric JSON Format

Metric is represented as simple flat JSON objects with the following keys:

NameTypeDescription
metricIdstringThe id of the dataset metric which needs to be queried in the report.
namestringName of the metric. This will be used as the key field in the result set.
aggregatorenumMust be one of metric's availableAggregators.
  • Response:

A list of query results grouped by the specified groups. The fields determined based on the groupBys and metrics in the query request body.

  • Example

When you want to get the number of chats of a specific agent and present the results by day, you only need to simply configure the query request and configure it in the corresponding field.

  • Request
curl https://api11.comm100.io/reporting/query?siteid=10000 \
-X 'GET' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json' \
-D '{
  "dataSetId": "Chat",
  "metrics": [
      {
          "metricId": "Chats",
          "aggregator": "count",
          "name": "chats_count"
      }
  ],
  "groupBys": [
      {
          "attributeId": "ChatRequestedTime",
          "timeDisplayType": "day",
          "name": "chatrequestedtime_day"
      }
  ],
  "filters": [
      {
          "attributeId": "ChatAgent",
          "filterValues": [
              "67f44eb6-34f3-46d9-afe5-310ee7607368"
          ]
      }
  ],
  "timeZone": "Iran Standard Time"
}'
  • Response
    HTTP/1.1 200 OK
[
  {
      "chats_count": 1,
      "chatrequestedtime_day": "2022-09-30"
  },
  {
      "chats_count": 0,
      "chatrequestedtime_day": "2022-10-01"
  },
  ...
]

Was this article helpful?

What's Next