Views

Generate View Aggregation Data

Generate aggregation results for a view. This endpoint executes the view's aggregations against transformations from the specified functions, applies the defined filters, and returns aggregated values. The request includes the view configuration (columns, filters, aggregations, function IDs) and a time window to filter transformations by creation date. The response contains an array of aggregation results, where each aggregation contains groups and their aggregated values. For grouped aggregations, multiple groups are returned (up to 200 groups per aggregation). For non-grouped aggregations, a single group with an empty group name is returned. Supported aggregation functions include count (total count of rows), count_distinct (count of unique values in a column), sum (sum of numeric values), average (average of numeric values), min (minimum numeric value), and max (maximum numeric value). Note: The functions field in the view configuration is required. At least one function ID or name must be specified.

POST
/v2/views/aggregation-data
x-api-key<token>

Authenticate using API Key in request header

In: header

Request Body

application/json

name*string

Name of the view

columns*

List of columns in the view

filters*

List of filters applied to the view

aggregations*

List of aggregations defined for the view

functions*

List of functions that this view queries transformations from

timeWindow*

Time window for filtering transformations in a view

Response Body

application/json

application/json

curl -X POST "https://api.bem.ai/v2/views/aggregation-data" \  -H "Content-Type: application/json" \  -d '{    "name": "Invoice Overview",    "columns": [      {        "name": "Invoice Number",        "valueSchemaPath": [          "invoiceDetails",          "invoiceNumber"        ],        "displayOrderIndex": 0      }    ],    "filters": [      {        "columnName": "Invoice Amount",        "filterType": "equals_string"      }    ],    "aggregations": [      {        "name": "Total Revenue",        "function": "count"      }    ],    "functions": [      {        "id": "string",        "name": "string"      }    ],    "timeWindow": {      "start": "2024-01-01T00:00:00Z",      "end": "2024-01-31T23:59:59Z"    }  }'
{
  "aggregations": [
    {
      "name": "Total Revenue",
      "groups": [
        {
          "groupName": "Customer A",
          "value": 5000
        }
      ]
    }
  ]
}
{
  "message": "invalid request body: missing required field 'transformationIDs'",
  "code": 400,
  "details": {
    "field": "transformationIDs",
    "reason": "required field missing"
  }
}