---
title: Aggregate cases
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Case Management
---

# Aggregate cases{% #aggregate-cases %}

{% tab title="v2" %}
**Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
| Datadog site      | API endpoint                                              |
| ----------------- | --------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/cases/aggregate |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/cases/aggregate |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/cases/aggregate      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/cases/aggregate      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/cases/aggregate  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/cases/aggregate     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/cases/aggregate |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/cases/aggregate |

### Overview

Performs an aggregation query over cases, grouping results by specified fields and returning counts per group along with a total. Useful for dashboards and analytics.

OAuth apps require the `cases_read` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#case-management) to access this endpoint.



### Request

#### Body Data (required)

Case aggregate request payload.

{% tab title="Model" %}

| Parent field | Field                          | Type     | Description                                                                                                                   |
| ------------ | ------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]         | object   | Data object wrapping the aggregation query type and attributes.                                                               |
| data         | attributes [*required*]   | object   | Attributes for the aggregation request, including the search query and grouping configuration.                                |
| attributes   | group_by [*required*]     | object   | Configuration for grouping aggregated results by one or more case fields.                                                     |
| group_by     | groups [*required*]       | [string] | Fields to group by.                                                                                                           |
| group_by     | limit [*required*]        | int32    | Maximum number of groups to return.                                                                                           |
| attributes   | query_filter [*required*] | string   | A search query to filter which cases are included in the aggregation. Uses the same syntax as the Case Management search bar. |
| data         | type [*required*]         | enum     | JSON:API resource type for case aggregation requests. Allowed enum values: `aggregate`                                        |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "group_by": {
        "groups": [
          "status"
        ],
        "limit": 14
      },
      "query_filter": "service:case-api"
    },
    "type": "aggregate"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response containing aggregated case counts grouped by the requested fields.

| Parent field | Field                        | Type     | Description                                                                                                     |
| ------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]       | object   | Data object containing the aggregation results, including total count and per-group breakdowns.                 |
| data         | attributes [*required*] | object   | Attributes of the aggregation result, including the total count across all groups and the per-group breakdowns. |
| attributes   | groups [*required*]     | [object] | Aggregated groups.                                                                                              |
| groups       | group [*required*]      | string   | The value of the field being grouped on (for example, `OPEN` when grouping by status).                          |
| groups       | value [*required*]      | [number] | The count of cases in this group.                                                                               |
| attributes   | total [*required*]      | double   | Total count of aggregated cases.                                                                                |
| data         | id [*required*]         | string   | Aggregate response identifier.                                                                                  |
| data         | type [*required*]       | string   | Aggregate resource type.                                                                                        |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "groups": [
        {
          "group": "OPEN",
          "value": [
            42
          ]
        }
      ],
      "total": 100
    },
    "id": "agg-result-001",
    "type": "aggregate"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="401" %}
Unauthorized
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Forbidden
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="404" %}
Not Found
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/cases/aggregate" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "group_by": {
        "groups": [
          "status"
        ],
        "limit": 14
      },
      "query_filter": "service:case-api"
    },
    "type": "aggregate"
  }
}
EOF 
                
{% /tab %}
