# Update analytics sharing

`POST https://api.chat-data.com/api/v2/update-metrics-share`

Canonical: https://www.chat-data.com/api-reference/update-metrics-share

## 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

This API endpoint allows you to configure analytics sharing settings for your chatbot. The response always contains the link of the public analytics dashboard. Setting `public` requires a [plan](/pricing) that includes sharing analytics. Only the fields you send are changed.

## Request body (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| chatbotId | string | yes | The ID of the chatbot to update. |
| public | boolean | no | Whether to make analytics publicly accessible. |
| selected | array of string | no | List of graphs to display in the public analytics view. |

Send only the fields you want to set; optional fields you omit are left unchanged.

## Example request

```bash
curl 'https://api.chat-data.com/api/v2/update-metrics-share' \
  -H "Authorization: Bearer $CHAT_DATA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "chatbotId": "6650f1c2a9e4b83d2c7a1f05"
}'
```

## Example response (200)

```json
{
  "status": "success",
  "analyticsLink": "https://chat.example.com/analytics/n1GHt-Fw0EVmdEl73m1cWv2SLMnGZTSC1T3laTk_ce5sRBcMwr4ZOz8QEiXty82bCKdiXsP0oiYbf2m8-Qq3g2_uMaTcnFwpAvcOrVaCDl5lwsqdik6rZS3WJkbcxlrNRH7Br6TcoteQug28Jr5PpcjwMPgL6goV47eTgccupFAkDodqz4qTIlkqVlE"
}
```

## Responses

| Status | Description |
| --- | --- |
| 200 | Successful response. |
| 400 | An item in `selected` is not one of the allowed graph names. |
| 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. Also returned when `public` is set and the plan does not include sharing analytics. |
| 404 | `chatbotId` was not provided. |
| 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. |
