# Get analytics

`GET https://api.chat-data.com/api/v2/get-analysis/{chatbotId}`

Canonical: https://www.chat-data.com/api-reference/get-analysis

## Authentication

Send an API key as a Bearer token: `Authorization: Bearer $CHAT_DATA_API_KEY`. Workspace keys reach every chatbot in the workspace; chatbot-scoped keys reach only their chatbot. Keep keys on the server.

## Description

Get the aggregated statistics of a chatbot.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| chatbotId | path | string | yes | The unique identifier allocated to the chatbot. |
| startTimestamp | query | number | no | Start of the time range (inclusive), in milliseconds since the Unix epoch. Statistics are stored per UTC day, each dated at 00:00 UTC. |
| endTimestamp | query | number | no | End of the time range (inclusive), in milliseconds since the Unix epoch. |
| source | query | array of string | no | Filter analytics by source. Repeat the parameter to match several sources. |

## Example request

```bash
curl 'https://api.chat-data.com/api/v2/get-analysis/6650f1c2a9e4b83d2c7a1f05' \
  -H "Authorization: Bearer $CHAT_DATA_API_KEY"
```

## Example response (200)

```json
{
  "status": "success",
  "countryDistribution": [
    {
      "country": "US",
      "count": 184
    },
    {
      "country": "GB",
      "count": 61
    }
  ],
  "hourDistribution": [
    {
      "hour": "14",
      "source": "iframe",
      "count": 37
    },
    {
      "hour": "15",
      "source": "iframe",
      "count": 29
    }
  ],
  "creditsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 96
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 412
    }
  ],
  "messagesDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 88
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 356
    }
  ],
  "liveChatEmailsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 1
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 3
    }
  ],
  "liveChatSmsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 0
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 2
    }
  ],
  "liveChatEscalationsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 1
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 4
    }
  ],
  "upVotesDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 6
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 21
    }
  ],
  "downVotesDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 1
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 4
    }
  ],
  "conversationsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 14
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 58
    }
  ],
  "leadsCountDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 2
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 9
    }
  ],
  "workflowEmailsDistribution": [
    {
      "date": 1791849600000,
      "source": "api",
      "count": 1
    },
    {
      "date": 1791936000000,
      "source": "iframe",
      "count": 5
    }
  ],
  "topicsDistribution": [
    {
      "topic": "Pricing",
      "count": 26
    },
    {
      "topic": "Shipping",
      "count": 17
    }
  ],
  "sentimentsDistribution": [
    {
      "sentiment": "positive",
      "count": 41
    },
    {
      "sentiment": "neutral",
      "count": 12
    }
  ],
  "ratingDistribution": [
    {
      "rating": "5",
      "count": 19
    },
    {
      "rating": "4",
      "count": 7
    }
  ]
}
```

## Responses

| Status | Description |
| --- | --- |
| 200 | Successful response. |
| 400 | An unexpected error occurred while processing the request; `message` contains the error. |
| 401 | Authentication failed: the `Authorization` header is missing or not in the `Bearer <key>` format, the API key does not exist, its workspace is unavailable or has no owner, or the workspace's plan does not include API access. `message` says which. |
| 403 | The API key cannot access the requested chatbot. A chatbot-scoped key used with another chatbot's ID gets `Access denied to this chatbot`. A workspace key gets `Chatbot <id> was not found in this API key's workspace. It may have been deleted or moved to another workspace.` when the chatbot does not exist or belongs to another workspace. |
| 429 | The workspace sent more than 600 API requests in the last minute. Wait the number of seconds given in the `Retry-After` header (and in `message`) before retrying. |
