---
name: azion-query-aggregated-data-with-graphql
description: >-
  Total the bytes your applications sent per time bucket with an aggregated GraphQL API query to the metrics endpoint, from curl or any HTTP client.
---

# Query aggregated data with GraphQL

You can read totals over time from the [GraphQL API](/en/documentation/devtools/graphql/overview/) with an aggregated query, sent from `curl` or any other HTTP client.

Aggregated data is request data that the metrics endpoint stores grouped into time buckets. An aggregated query applies a function, such as `sum`, to one field and returns one row per group. For the rules of an aggregated query, refer to [Queries](/en/documentation/devtools/graphql/queries/#aggregated-data). The example below reads the `workloadMetrics` dataset. The `httpMetrics` dataset is deprecated and returns the same rows; use `workloadMetrics`. For the datasets of each endpoint, refer to [Features](/en/documentation/devtools/graphql/features/).

---

## Prerequisites

- A personal token. To create one, refer to [How to manage a personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- An application on [Applications](/en/documentation/platform/applications/) that received requests during the time window you query.
- `curl`, or another HTTP client that sends `POST` requests. To run a query from the GraphiQL Playground instead, refer to the [GraphQL API quickstart](/en/documentation/devtools/graphql/first-steps/).

---

## Total the bytes sent per time bucket

This query adds up `bytesSent`, the bytes sent to clients, for each time bucket of a seven-day window. To run it:

1. **Write the query**

   Set `begin` and `end` in `tsRange` to the window you want to read, in the `YYYY-MM-DDTHH:mm:ss` format:

   ```graphql
   query HttpQuery {
     workloadMetrics(
       limit: 10,
       filter: {
         tsRange: {begin:"2026-09-26T14:00:00", end:"2026-10-03T14:00:00"}
       }
       aggregate: {sum: bytesSent}
       groupBy: [ts]
       orderBy: [ts_ASC]
     )
     {
       ts
       sum
     }
   }
   ```

2. **Send the query**

   Send the query in the `query` key of a JSON body to `https://api.azion.com/v4/metrics/graphql`. Replace `[TOKEN VALUE]` with your personal token:

   ```bash
   curl -X POST 'https://api.azion.com/v4/metrics/graphql' \
     -H 'Content-Type: application/json' \
     -H 'Authorization: Token [TOKEN VALUE]' \
     -d '{"query":"query HttpQuery { workloadMetrics(limit: 10, filter: { tsRange: {begin: \"2026-09-26T14:00:00\", end: \"2026-10-03T14:00:00\"} }, aggregate: {sum: bytesSent}, groupBy: [ts], orderBy: [ts_ASC]) { ts sum } }"}'
   ```

3. **Read the response**

   The API answers `200` with 10 rows. The response below is cut after its first three rows:

   ```json
   {
     "data": {
       "workloadMetrics": [
         {
           "ts": "2026-09-26T16:00:00Z",
           "sum": 104492
         },
         {
           "ts": "2026-09-27T18:00:00Z",
           "sum": 1100
         },
         {
           "ts": "2026-09-27T22:00:00Z",
           "sum": 14088
         },
         …
       ]
     }
   }
   ```

Each row holds the start of a time bucket in `ts`, in UTC, and the bytes sent during it in `sum`, oldest bucket first. For a seven-day window, the buckets are one hour long, and an hour with no requests returns no row. The length of the window sets the bucket size, as [How the GraphQL API works](/en/documentation/devtools/graphql/overview/) describes. An empty `workloadMetrics` array means that no request matched the window.

Three arguments shape the result:

| Argument    | In the example     | What it does                                                                                                                                                              |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aggregate` | `{sum: bytesSent}` | Applies the `sum` function to the `bytesSent` field. The result comes back in a field named after the function, `sum`.                                                    |
| `groupBy`   | `[ts]`             | Returns one row per value of the listed fields. `[ts]` returns one row per time bucket. Without `groupBy`, the response holds one row with the total of the whole window. |
| `orderBy`   | `[ts_ASC]`         | Sorts the rows by a field and a direction suffix. `ts_ASC` lists the oldest bucket first, `ts_DESC` the latest first, and `sum_DESC` the highest total first.             |

To total another field, replace `bytesSent` in `aggregate`, such as with `requestTime` or `requests`. For the fields that each function accepts, refer to [Queries](/en/documentation/devtools/graphql/queries/#aggregate-functions).

---

## Next steps

- [Find the top values with GraphQL](/en/documentation/guides/platform/observability/graphql-top-x-query.md): Rank the most frequent values of a field, such as hosts or status codes.
- [Real-Time Metrics fields](/en/documentation/devtools/graphql/gql-real-time-metrics-fields.md): Every field of workloadMetrics and the other Metrics datasets.
- [GraphQL API limits](/en/documentation/devtools/graphql/limits.md): The row cap, the field cap, and the time-window bounds of a query.
- [Run GraphQL queries in Postman](/en/documentation/guides/platform/observability/query-graphql-postman.md): Send the same query from Postman instead of curl.
