# Activities

> Manage conversations and contact interactions

- Page: https://tbit.app/docs/api/activities
- Base URL: `https://rest-api.tbit.app/v1`
- Authentication: `X-API-Key` header with your key on every request (the examples read it from the `TBIT_API_KEY` environment variable)

## Overview

Activities represent conversations between your agent and contacts. Each activity tracks a conversation across one or more channels, including status, tags, and assignment.

## Endpoints

| Method | Path | Description |
| --- | --- | --- |
| `GET` | `/v1/activities` | List activities |
| `GET` | `/v1/activities/:id` | Get activity detail |
| `PATCH` | `/v1/activities/:id` | Update activity |
| `POST` | `/v1/activities/:id/tags` | Add tags to activity |
| `DELETE` | `/v1/activities/:id/tags?tag_id=X` | Remove tag from activity |

## Query Parameters

The list endpoint supports the following query parameters:

| Parameter | Type | Description |
| --- | --- | --- |
| `limit` | `number` | Results per page (default: 20, max: 100) |
| `offset` | `number` | Number of results to skip (default: 0) |
| `status` | `string` | Filter by status: open, closed, pending |
| `tag` | `string` | Filter by tag ID |
| `search` | `string` | Search by contact name or phone number |

## List Activities

`GET /v1/activities`

```bash
curl "https://rest-api.tbit.app/v1/activities?limit=20&offset=0&status=open" \
  -H "X-API-Key: $TBIT_API_KEY"
```

## Get Activity Detail

`GET /v1/activities/64f1a2b3c4d5e6f7a8b9c0d1`

```bash
curl "https://rest-api.tbit.app/v1/activities/64f1a2b3c4d5e6f7a8b9c0d1" \
  -H "X-API-Key: $TBIT_API_KEY"
```

## Update Activity

`PATCH /v1/activities/64f1a2b3c4d5e6f7a8b9c0d1`

```bash
curl -X PATCH "https://rest-api.tbit.app/v1/activities/64f1a2b3c4d5e6f7a8b9c0d1" \
  -H "X-API-Key: $TBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "closed",
    "assigned_to": "agent_user_id",
    "profile_name": "John Doe"
  }'
```

## Add Tags

`POST /v1/activities/64f1a2b3c4d5e6f7a8b9c0d1/tags`

```bash
curl -X POST "https://rest-api.tbit.app/v1/activities/64f1a2b3c4d5e6f7a8b9c0d1/tags" \
  -H "X-API-Key: $TBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tag_ids": [
      "tag_id_1",
      "tag_id_2"
    ]
  }'
```

## Remove Tag

`DELETE /v1/activities/64f1a2b3c4d5e6f7a8b9c0d1/tags`

```bash
curl -X DELETE "https://rest-api.tbit.app/v1/activities/64f1a2b3c4d5e6f7a8b9c0d1/tags?tag_id=tag_id_1" \
  -H "X-API-Key: $TBIT_API_KEY"
```

## Response Format

List endpoints return paginated results:

```json
{
  "data": [
    {
      "id": "64f1a2b3c4d5e6f7a8b9c0d1",
      "status": "open",
      "profile_name": "John Doe",
      "channel_identifiers": ["573001234567"],
      "tags": [
        { "id": "tag_1", "name": "VIP", "color": "#ef4444" }
      ],
      "assigned_to": null,
      "created_at": "2024-09-01T12:00:00Z",
      "updated_at": "2024-09-01T14:30:00Z"
    }
  ],
  "pagination": {
    "total": 100,
    "limit": 20,
    "offset": 0,
    "has_more": true
  }
}
```
