- Url
- /V2.0/services/data/aggregateQuery
- HTTP Method
GET,POST
- Description
- Performs a query and aggreagtes (and optionally groups) the results using one of the grouping functions (e.g. Count, Sum, etc.)
- Parameters
-
Name Type Description typeName* string The main entity type to query (e.g. WorkItem
,User
etc.)groupBy string[] A list of field names to group results by orders orderBy[] Optionaly order the result where condition The query criteria aggregations* fieldAggregation[] List of aggregations to perform paging paging Paging setting for the query - Result
- An object containing the results from a query
Name Type Description entities entity[] Array of entities returned from this query paging paging Paging information returned from this query. If paging.hasMore
is true, this object should be passed as is, to the same query API in order to retrieve the next pageIn case of failure an error object will be returned
* indicates required fields - Samples
- The following example show a query which returns the count of tasks grouped by state. The count function is given an alias named Cnt so it will be easy to sort by it.
POST /V2.0/services/data/aggregateQuery
{ "typeName": "Task", "aggregations": [ { "function": "Count", "fieldName": "Name", "alias": "Cnt" } ], "groupBy": [ "State" ], "orders": [ { "fieldName": "Cnt", "order": "Descending" } ] }
Response:{ "entities": [ { "id": null, "State": { "id": "/State/Draft" }, "Cnt": 73.0 }, { "id": null, "State": { "id": "/State/Completed" }, "Cnt": 41.0 }, { "id": null, "State": { "id": "/State/Active" }, "Cnt": 17.0 }, { "id": null, "State": { "id": "/State/On Hold" }, "Cnt": 10.0 }, { "id": null, "State": { "id": "/State/Cancelled" }, "Cnt": 1.0 } ], "paging": { "from": 5, "limit": 100, "hasMore": false } }