POST

Aggregate Data Items


Runs an aggregation on a data collection and returns the resulting list of items.

An aggregation enables you to perform certain calculations on your collection data, or on groups of items that you define, to retrieve meaningful summaries. You can also add paging, filtering, and sorting preferences to your aggregation to retrieve exactly what you need.

Authentication

You can only call this method when authenticated as a Wix app or Wix user identity.

Permissions
Manage All Data Resources
Manage Data Items
Read Data Items
Learn more about app permissions.
Endpoint
POST
https://www.wixapis.com/wix-data/v2/items/aggregate

Body Params
dataCollectionIdstringRequiredmaxLength 256

ID of the collection on which to run the aggregation.


initialFilterstruct

Filter applied to the collection's data prior to running the aggregation. See API Query Language for information on how to structure a filter object.

Note: The values you provide for each filter field must adhere to that field's type. For example, when filtering by a field whose type is Date and Time, use an object in the following format: "someDateAndTimeFieldKey": { "$date": "YYYY-MM-DDTHH:mm:ss.sssZ"}. Learn more about data types in Wix Data.


aggregationAggregation

Aggregation applied to the data.


finalFilterstruct

Filter applied to the processed data following the aggregation. See API Query Language for information on how to structure a filter object. Note: The values you provide for each filter field must adhere to that field's type. For example, when filtering by a field whose type is Date and Time, use an object in the following format: "someDateAndTimeFieldKey": { "$date": "YYYY-MM-DDTHH:mm:ss.sssZ"}. Learn more about data types in Wix Data.


sortArray <Sorting>maxItems 100

Sort object in the following format: [{"fieldName":"sortField1","order":"ASC"},{"fieldName":"sortField2","order":"DESC"}]


returnTotalCountboolean

Whether to return the total count in the response for a query with offset paging. When true, the pagingMetadata object in the response contains a total field.

Default: false


consistentReadboolean

Whether to retrieve data from the primary database instance. This decreases performance but ensures data retrieved is up to date even immediately after an update. Learn more about Wix Data and eventual consistency.

Default: false


languagestringformat LANGUAGE_TAG

Language to translate result text into, in IETF BCP 47 language tag format. If provided, the result text is returned in the specified language. Note: Translation for the specified language must be enabled for the collection in Wix Multilingual.

If not provided, result text is not translated.


appOptionsstruct

Additional parameters specific to the Wix app collection you are querying.

When querying the Wix Stores Products collection, pass the following optional parameters:

  • includeHiddenProducts: Whether to include hidden products in the response. Default: false.
  • includeVariants: Whether to include product variants in the query. Default: false.

publishPluginOptionsPublishPluginOptions

Options for the Publish plugin. This plugin allows items in a data collection to be marked as draft or published. Published items are visible to site visitors, while draft items are not.


One Of
Choose one of the following parameters

pagingPaging

Paging options to limit and skip the number of items.


cursorPagingCursorPaging

Cursor token pointing to a page of results. Not used in the first request. Following requests use the cursor token and not filter or sort.

Response Object
resultsArray <object>

Aggregation results.


pagingMetadataPagingMetadata

Paging information.

Request
cURL
curl -X POST \ 'https://www.wixapis.com/wix-data/v2/items/aggregate' \ -H 'Content-Type: application/json' \ -H 'Authorization: <AUTH>' \ -d '{ "dataCollectionId": "cities", "initialFilter": { "year": 2022 }, "aggregation": { "groupingFields": ["state"], "operations": [ { "resultFieldName": "totalPopulation", "sum": { "itemFieldName": "population" } } ] } }'
Response
JSON
{ "results": [ { "_id": { "state": "New York" }, "totalPopulation": 20000000.0, "state": "New York" }, { "_id": { "state": "California" }, "totalPopulation": 39000000.0, "state": "California" } ], "pagingMetadata": { "count": 2, "tooManyToCount": false, "hasNext": false } }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?