# Query Top URLs Impacted by Bots with GraphQL

The **botManagerBreakdownMetrics** dataset provides access to real-time aggregated data from Azion Bot Manager activity, related to requests classified as bots and bad bots across your applications, as well as the URLs most impacted by bots access. This dataset is part of the Real-Time Metrics GraphQL API and is generated from the requests analyzed and identified as bots and bad bots.

This information can be accessed through the GraphQL API. Additionally, this data is retained and available for up to *60 days*.

This guide explains how to query the top 5 URLs impacted by bot activity.

:::note
To retrieve this data, you must be subscribed to Azion Bot Manager and use the [GraphQL API](/en/documentation/devtools/graphql-api/overview/). Contact the [Sales team](https://www.azion.com/en/contact/) for more details on the subscription.
:::

---

## Querying data

To query the top 5 URLs impacted by bot activity, proceed as follows:

1. Access the GraphiQL Playground at this link: `https://api.azion.com/v4/metrics/graphql`.
    - You must be logged in to your Azion account. Otherwise, you'll receive an error message.
2. Send a query following this format:

```graphql
query {
  botManagerBreakdownMetrics (
    filter: {
      tsRange: {
        begin: "2024-10-01T00:00:00"
        end: "2024-10-03T00:00:00"
      }
    }
    aggregate: {
      sum: botRequests
    }
    groupBy: [requestUrl]
    orderBy: [sum_DESC]
    limit: 5
  ) {
    requestUrl
    sum
  }
}
```

Where:

| Field | Description |
|----------|----------|
| `filter` | Defines the criteria used to filter the data returned by the query |
| `tsRange` | A subfield of `filter`. Specifies a time range for filtering data. It includes `begin` and `end` fields to define the start and end timestamps. Format: `"YYYY-MM-DDTHH:mm:ss"`; example: `"2024-04-11T00:00:00"` |
| `sum: botRequests` | Returns the total number of requests classified as bots within the specified time range, after applying any filters |
| `orderBy` | Specifies the order in which the results should be returned. Examples: `[sum_DESC]`, for descending order, and `[sum_ASC]`, for ascending order |
| `groupBy` | Specifies the fields by which the query results should be grouped. Example: `[requestUrl]` to group by URL |
| `limit` | Specifies the maximum number of results to return. In this case, `5` |

:::note
This example retrieves data for `requestUrl`, the impacted URLs, and the total (sum) of requests identified as bots during the specified time range, grouped by the selected fields. To know more about the available fields, check the [Real-Time Metrics GraphQL API Fields documentation](/en/documentation/devtools/graphql-api/features/gql-real-time-metrics-fields/).
:::

3. You'll receive a response similar to this: 

```graphql
{
  "data": {
    "botManagerBreakdownMetrics": [
      {
        "requestUrl": "example-host1.com/api/v1/resource",
        "sum": 333543
      },
      {
        "requestUrl": "example-host2.net/api/v2/data",
        "sum": 107281
      },
      {
        "requestUrl": "example-host3.org/api/v3/info",
        "sum": 103363
      },
      {
        "requestUrl": "example-host4.io/api/v4/details",
        "sum": 89668
      },
      {
        "requestUrl": "example-host5.co/api/v5/summary",
        "sum": 64060
      }
    ]
  }
}
```

Where: 

| Field | Description |
|----------|----------|
| `requestUrl` | URL impacted by bot activity. Example: `example-host5.co/api/v5/summary` |
| `sum` | Total requests involving bot activity received by the URL. This field is the result of a sum. Example: `333543` |

:::tip
To know more about the available fields, check the [Real-Time Metrics GraphQL API Fields documentation](/en/documentation/devtools/graphql-api/features/gql-real-time-metrics-fields/).
:::