# REST API

Tickets, messages, customers and the people who answer them. The API lives on your workspace's own address and every request carries an API key.

Everything here is also described in the [OpenAPI document](https://www.lagottolabs.ai/openapi.json) (OpenAPI 3.1), which this page is generated from.

## Authentication

Every request carries an API key as a bearer token. An administrator creates keys in the workspace under **Settings, API keys**.

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/me \\
  -H "Authorization: Bearer $API_TOKEN"
```

- The API lives on **your workspace's own address**: `https://YOUR-WORKSPACE.lagottolabs.ai/api/v1`. A key only works there. Sent to any other workspace it is a 401.
- A key **acts as a person** in your workspace. Replies and notes it posts are in their name, and it can never do more than they can.
- A key is **read and write** or **read only**. A read-only key, or a key acting as somebody with a read-only seat, gets a 403 on anything that changes data.
- A key stops working the moment it is revoked, it expires, or its person is deactivated.
- The token is shown once. We keep only a fingerprint, so a lost token is replaced, not recovered. Keep it out of browsers and mobile apps: anyone holding it can read your tickets.

## Requests and responses

- Send JSON with `Content-Type: application/json`. Every answer is JSON.
- A single record comes back as `{ "data": { ... } }`, a list as `{ "data": [ ... ], "pagination": { ... } }`.
- Times are ISO 8601 in UTC, like `2026-01-30T14:05:09Z`.
- Tickets are addressed by their `number`, the one your agents and customers see. Everything else is addressed by `id`.
- Message bodies are plain text or Markdown.
- A `PATCH` changes only the fields you send.

## Pagination

Lists take `page` (from 1) and `per_page` (default 25, at most 100). The answer says how many there are in all and which page comes next: `next_page` is `null` on the last one.

```
{
  "data": [],
  "pagination": {
    "page": 2,
    "per_page": 25,
    "total": 61,
    "next_page": 3
  }
}
```

To keep another system in step, list tickets with `updated_since`: they come oldest change first, so paging stays stable while tickets keep changing.

## Errors

The status code says what kind of problem it is, and the body is always the same shape. `type` is for your code, `message` is for a person, and `details` appears on a 422 with each field that was refused.

```
{
  "error": {
    "type": "validation_failed",
    "message": "Some fields are not valid.",
    "details": {
      "body": [
        "can't be blank"
      ]
    }
  }
}
```

| Status | Type | Meaning |
| --- | --- | --- |
| 400 | `bad_request` | A parameter is malformed, or the body is not valid JSON. |
| 401 | `unauthorized` | The token is missing, wrong, revoked, expired, or belongs to another workspace. |
| 403 | `forbidden` | The token is read-only, or acts as somebody with a read-only seat. |
| 404 | `not_found` | Nothing with that number or id in your workspace. |
| 422 | `validation_failed` | A field is not acceptable. details says which, and why. |
| 429 | `rate_limited` | Too many requests. Retry-After says how long to wait. |
| 500 | `server_error` | Our fault. Safe to retry, with an Idempotency-Key on anything that creates. |

## Rate limits

Each token may make **300 requests a minute**. Every answer carries `RateLimit-Limit` and `RateLimit-Remaining`. Past the limit you get a 429 with a `Retry-After` header: the number of seconds until the minute turns over. Wait that long and carry on.

## Idempotency

A network failure can leave you not knowing whether a ticket was opened or a reply was sent. Send an `Idempotency-Key` header (any string up to 255 characters, unique to the thing you are creating) when you open a ticket or add a message. A retry with the same key returns what the first request made, with a 200 instead of a 201, and creates and sends nothing more.

```
curl -X POST https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets \\
  -H "Authorization: Bearer $API_TOKEN" \\
  -H "Content-Type: application/json" \\
  -H "Idempotency-Key: contact-form-8f14e45f" \\
  -d '{ "customer": { "email": "carol@example.com" }, "body": "I was charged twice." }'
```

## Tickets

A conversation with a customer. Tickets are addressed by their number, the one agents and customers see.

### List tickets

GET `/api/v1/tickets`

Open tickets by default, most recent activity first. Spam is never listed. With `updated_since` the order is oldest change first, so a sync can page through without missing a ticket that changes meanwhile. With `q` the order is by relevance.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `status` | query | string | Which tickets to list. One of `open`, `closed`, `all`. Default `open`. |
| `assignee_id` | query | integer | Only tickets assigned to this user. |
| `unassigned` | query | boolean | `true` for only tickets nobody holds: no assignee, or one who has been deactivated. |
| `group_id` | query | integer | Only tickets routed to this group. |
| `customer_email` | query | string | Only tickets from the customer with exactly this address. |
| `q` | query | string | Search the ticket number, the customer, the subject and the thread. |
| `updated_since` | query | string | Only tickets changed at or after this time (ISO 8601). A new message counts as a change. |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of tickets.

```
{
  "data": [
    {
      "number": 1042,
      "subject": "Charged twice this month",
      "status": "open",
      "spam": false,
      "source": "api",
      "language": "en",
      "cc": [
        "accounts@example.com"
      ],
      "customer": {
        "id": 381,
        "email": "carol@example.com",
        "name": "Carol Customer"
      },
      "assignee": {
        "id": 12,
        "name": "Alice Agent",
        "email": "alice@yourcompany.com"
      },
      "group": {
        "id": 3,
        "name": "Billing"
      },
      "url": "https://your-workspace.lagottolabs.ai/tickets/1042",
      "created_at": "2026-01-30T14:05:09Z",
      "updated_at": "2026-01-30T14:05:09Z",
      "closed_at": null,
      "first_response_at": null,
      "last_customer_message_at": "2026-01-30T14:05:09Z",
      "last_agent_reply_at": null,
      "last_activity_at": "2026-01-30T14:05:09Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Open a ticket

POST `/api/v1/tickets`

Opens a ticket as a message from a customer, the way an email would: the customer is found by address or created, your routing triggers run, and the people who asked to hear about new tickets are notified. Nothing is sent to the customer. Send an `Idempotency-Key` header to make a retry safe.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | header | string | Any string of your choosing, up to 255 characters, unique to the thing you are creating. A retry with the same key returns what the first request made instead of making it again. |

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `customer` required | object | Who the ticket is from. Found by address, or created. Fields: `email` (required), `name`. |
| `subject` | string | Defaults to "(no subject)". |
| `body` required | string | The customer's message, as plain text or Markdown. |
| `cc` | array of string | Addresses to copy on every reply. |

#### Example request

```
curl -X POST https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "customer": {
    "email": "carol@example.com",
    "name": "Carol Customer"
  },
  "subject": "Charged twice this month",
  "body": "I was charged twice this month. Can you refund the duplicate?",
  "cc": [
    "accounts@example.com"
  ]
}'
```

#### Example response 200 · The ticket an earlier request with the same `Idempotency-Key` opened. Nothing new was created.

```
{
  "data": {
    "number": 1042,
    "subject": "Charged twice this month",
    "status": "open",
    "spam": false,
    "source": "api",
    "language": "en",
    "cc": [
      "accounts@example.com"
    ],
    "customer": {
      "id": 381,
      "email": "carol@example.com",
      "name": "Carol Customer"
    },
    "assignee": {
      "id": 12,
      "name": "Alice Agent",
      "email": "alice@yourcompany.com"
    },
    "group": {
      "id": 3,
      "name": "Billing"
    },
    "url": "https://your-workspace.lagottolabs.ai/tickets/1042",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z",
    "closed_at": null,
    "first_response_at": null,
    "last_customer_message_at": "2026-01-30T14:05:09Z",
    "last_agent_reply_at": null,
    "last_activity_at": "2026-01-30T14:05:09Z",
    "ai_summary": null,
    "ai_draft": "Hi Carol,\n\nI can see the two charges on 28 January. I've refunded the second one.",
    "ai_draft_note": "Refund not yet issued - the reply assumes you will issue it.",
    "ai_draft_at": "2026-01-30T14:06:40Z",
    "messages": [
      {
        "id": 90214,
        "type": "customer",
        "body": "I was charged twice this month. Can you refund the duplicate?",
        "author": {
          "type": "customer",
          "id": null,
          "name": "Carol Customer",
          "email": "carol@example.com"
        },
        "attachments": [
          {
            "filename": "invoice.pdf",
            "content_type": "application/pdf",
            "byte_size": 48213
          }
        ],
        "created_at": "2026-01-30T14:05:09Z"
      }
    ],
    "proposals": [
      {
        "id": 55,
        "kind": "code_fix",
        "status": "pending",
        "title": "Stop charging twice when a renewal is retried",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T14:06:40Z",
        "decided_at": null
      }
    ],
    "pull_requests": [
      {
        "number": 918,
        "kind": "code_fix",
        "state": "open",
        "title": "Stop charging twice when a renewal is retried",
        "url": "https://github.com/yourcompany/billing/pull/918",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T15:10:02Z",
        "merged_at": null,
        "closed_at": null
      }
    ]
  }
}
```

**201**: The ticket that was opened.

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Get a ticket

GET `/api/v1/tickets/{number}`

The ticket with its whole thread, the AI's unsent draft if there is one, and any fix proposals and pull requests made for it.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `number` required | path | integer | The ticket's number. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets/1042 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The ticket.

```
{
  "data": {
    "number": 1042,
    "subject": "Charged twice this month",
    "status": "open",
    "spam": false,
    "source": "api",
    "language": "en",
    "cc": [
      "accounts@example.com"
    ],
    "customer": {
      "id": 381,
      "email": "carol@example.com",
      "name": "Carol Customer"
    },
    "assignee": {
      "id": 12,
      "name": "Alice Agent",
      "email": "alice@yourcompany.com"
    },
    "group": {
      "id": 3,
      "name": "Billing"
    },
    "url": "https://your-workspace.lagottolabs.ai/tickets/1042",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z",
    "closed_at": null,
    "first_response_at": null,
    "last_customer_message_at": "2026-01-30T14:05:09Z",
    "last_agent_reply_at": null,
    "last_activity_at": "2026-01-30T14:05:09Z",
    "ai_summary": null,
    "ai_draft": "Hi Carol,\n\nI can see the two charges on 28 January. I've refunded the second one.",
    "ai_draft_note": "Refund not yet issued - the reply assumes you will issue it.",
    "ai_draft_at": "2026-01-30T14:06:40Z",
    "messages": [
      {
        "id": 90214,
        "type": "customer",
        "body": "I was charged twice this month. Can you refund the duplicate?",
        "author": {
          "type": "customer",
          "id": null,
          "name": "Carol Customer",
          "email": "carol@example.com"
        },
        "attachments": [
          {
            "filename": "invoice.pdf",
            "content_type": "application/pdf",
            "byte_size": 48213
          }
        ],
        "created_at": "2026-01-30T14:05:09Z"
      }
    ],
    "proposals": [
      {
        "id": 55,
        "kind": "code_fix",
        "status": "pending",
        "title": "Stop charging twice when a renewal is retried",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T14:06:40Z",
        "decided_at": null
      }
    ],
    "pull_requests": [
      {
        "number": 918,
        "kind": "code_fix",
        "state": "open",
        "title": "Stop charging twice when a renewal is retried",
        "url": "https://github.com/yourcompany/billing/pull/918",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T15:10:02Z",
        "merged_at": null,
        "closed_at": null
      }
    ]
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Update a ticket

PATCH `/api/v1/tickets/{number}`

Close or reopen it, assign it, route it to a group, or mark it as spam. Send only what should change. Everything is checked before anything is changed, and each change is recorded on the ticket in the name of the token's user. Closing a ticket may send the customer a satisfaction survey if your workspace uses them.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `number` required | path | integer | The ticket's number. |

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `status` | string | Close or reopen the ticket. One of `open`, `closed`. |
| `assignee_id` | integer or null | The user to assign it to, or null to unassign. Must be active and not a read-only seat. |
| `group_id` | integer or null | The group to route it to, or null for none. |
| `spam` | boolean | True marks it as spam and closes it; false brings it back, open. Cannot be combined with `status` when true. |

#### Example request

```
curl -X PATCH https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets/1042 \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "status": "closed",
  "assignee_id": 12,
  "group_id": 3,
  "spam": false
}'
```

#### Example response 200 · The ticket after the change.

```
{
  "data": {
    "number": 1042,
    "subject": "Charged twice this month",
    "status": "open",
    "spam": false,
    "source": "api",
    "language": "en",
    "cc": [
      "accounts@example.com"
    ],
    "customer": {
      "id": 381,
      "email": "carol@example.com",
      "name": "Carol Customer"
    },
    "assignee": {
      "id": 12,
      "name": "Alice Agent",
      "email": "alice@yourcompany.com"
    },
    "group": {
      "id": 3,
      "name": "Billing"
    },
    "url": "https://your-workspace.lagottolabs.ai/tickets/1042",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z",
    "closed_at": null,
    "first_response_at": null,
    "last_customer_message_at": "2026-01-30T14:05:09Z",
    "last_agent_reply_at": null,
    "last_activity_at": "2026-01-30T14:05:09Z",
    "ai_summary": null,
    "ai_draft": "Hi Carol,\n\nI can see the two charges on 28 January. I've refunded the second one.",
    "ai_draft_note": "Refund not yet issued - the reply assumes you will issue it.",
    "ai_draft_at": "2026-01-30T14:06:40Z",
    "messages": [
      {
        "id": 90214,
        "type": "customer",
        "body": "I was charged twice this month. Can you refund the duplicate?",
        "author": {
          "type": "customer",
          "id": null,
          "name": "Carol Customer",
          "email": "carol@example.com"
        },
        "attachments": [
          {
            "filename": "invoice.pdf",
            "content_type": "application/pdf",
            "byte_size": 48213
          }
        ],
        "created_at": "2026-01-30T14:05:09Z"
      }
    ],
    "proposals": [
      {
        "id": 55,
        "kind": "code_fix",
        "status": "pending",
        "title": "Stop charging twice when a renewal is retried",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T14:06:40Z",
        "decided_at": null
      }
    ],
    "pull_requests": [
      {
        "number": 918,
        "kind": "code_fix",
        "state": "open",
        "title": "Stop charging twice when a renewal is retried",
        "url": "https://github.com/yourcompany/billing/pull/918",
        "repository": "yourcompany/billing",
        "created_at": "2026-01-30T15:10:02Z",
        "merged_at": null,
        "closed_at": null
      }
    ]
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Messages

The thread on a ticket - what the customer wrote, what agents replied, and internal notes.

### List a ticket's messages

GET `/api/v1/tickets/{ticket_number}/messages`

The thread, oldest first, internal notes included.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `ticket_number` required | path | integer | The ticket's number. |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets/1042/messages \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of messages.

```
{
  "data": [
    {
      "id": 90214,
      "type": "customer",
      "body": "I was charged twice this month. Can you refund the duplicate?",
      "author": {
        "type": "customer",
        "id": null,
        "name": "Carol Customer",
        "email": "carol@example.com"
      },
      "attachments": [
        {
          "filename": "invoice.pdf",
          "content_type": "application/pdf",
          "byte_size": 48213
        }
      ],
      "created_at": "2026-01-30T14:05:09Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Add a message to a ticket

POST `/api/v1/tickets/{ticket_number}/messages`

What happens depends on `type`. A `reply` is **emailed to the customer** (and anyone copied on the ticket) from the token's user. A `note` is internal and is never sent. A `customer` message records something the customer told you elsewhere, such as your own contact form: it reopens a closed ticket and notifies your agents, exactly as an email from them would. Send an `Idempotency-Key` header to make a retry safe.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `ticket_number` required | path | integer | The ticket's number. |
| `Idempotency-Key` | header | string | Any string of your choosing, up to 255 characters, unique to the thing you are creating. A retry with the same key returns what the first request made instead of making it again. |

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `type` required | string | `reply` emails the customer. `note` is internal. `customer` records a message from the customer. One of `reply`, `note`, `customer`. |
| `body` required | string | Plain text or Markdown. |
| `close` | boolean | For a `reply` only - close the ticket once it is sent. |

#### Example request

```
curl -X POST https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/tickets/1042/messages \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "reply",
  "body": "Hi Carol,\n\nThe duplicate charge has been refunded. It should reach your card within five working days.",
  "close": true
}'
```

#### Example response 200 · The message an earlier request with the same `Idempotency-Key` added. Nothing new was created or sent.

```
{
  "data": {
    "id": 90214,
    "type": "customer",
    "body": "I was charged twice this month. Can you refund the duplicate?",
    "author": {
      "type": "customer",
      "id": null,
      "name": "Carol Customer",
      "email": "carol@example.com"
    },
    "attachments": [
      {
        "filename": "invoice.pdf",
        "content_type": "application/pdf",
        "byte_size": 48213
      }
    ],
    "created_at": "2026-01-30T14:05:09Z"
  }
}
```

**201**: The message that was added.

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Customers

The people who write in. Known by their email address.

### List customers

GET `/api/v1/customers`

Everyone who has written in, oldest first.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `email` | query | string | Only the customer with exactly this address. |
| `q` | query | string | Only customers whose name or address contains this. |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/customers \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of customers.

```
{
  "data": [
    {
      "id": 381,
      "email": "carol@example.com",
      "name": "Carol Customer",
      "language": "en",
      "created_at": "2026-01-30T14:05:09Z",
      "updated_at": "2026-01-30T14:05:09Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Create a customer

POST `/api/v1/customers`

Rarely needed: opening a ticket creates its customer. An address that is already a customer is a 422.

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `email` required | string |  |
| `name` | string |  |
| `language` | string |  |

#### Example request

```
curl -X POST https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/customers \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "carol@example.com",
  "name": "Carol Customer",
  "language": "en"
}'
```

#### Example response 201 · The customer that was created.

```
{
  "data": {
    "id": 381,
    "email": "carol@example.com",
    "name": "Carol Customer",
    "language": "en",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z"
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Get a customer

GET `/api/v1/customers/{id}`

The customer and their ten most recently active tickets.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` required | path | integer | The customer's id. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/customers/381 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The customer.

```
{
  "data": {
    "id": 381,
    "email": "carol@example.com",
    "name": "Carol Customer",
    "language": "en",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z",
    "recent_tickets": [
      {
        "number": 1042,
        "subject": "Charged twice this month",
        "status": "open",
        "spam": false,
        "source": "api",
        "language": "en",
        "cc": [
          "accounts@example.com"
        ],
        "customer": {
          "id": 381,
          "email": "carol@example.com",
          "name": "Carol Customer"
        },
        "assignee": {
          "id": 12,
          "name": "Alice Agent",
          "email": "alice@yourcompany.com"
        },
        "group": {
          "id": 3,
          "name": "Billing"
        },
        "url": "https://your-workspace.lagottolabs.ai/tickets/1042",
        "created_at": "2026-01-30T14:05:09Z",
        "updated_at": "2026-01-30T14:05:09Z",
        "closed_at": null,
        "first_response_at": null,
        "last_customer_message_at": "2026-01-30T14:05:09Z",
        "last_agent_reply_at": null,
        "last_activity_at": "2026-01-30T14:05:09Z"
      }
    ]
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Update a customer

PATCH `/api/v1/customers/{id}`

Send only what should change.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` required | path | integer | The customer's id. |

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `email` | string |  |
| `name` | string or null |  |
| `language` | string or null |  |

#### Example request

```
curl -X PATCH https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/customers/381 \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "carol@example.com",
  "name": "Carol Customer-Jones",
  "language": "en"
}'
```

#### Example response 200 · The customer after the change.

```
{
  "data": {
    "id": 381,
    "email": "carol@example.com",
    "name": "Carol Customer",
    "language": "en",
    "created_at": "2026-01-30T14:05:09Z",
    "updated_at": "2026-01-30T14:05:09Z"
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Users

The people in your workspace. Read-only.

### List users

GET `/api/v1/users`

Everyone in the workspace, including people who have been deactivated.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `active` | query | boolean | `true` to leave out people who have been deactivated. |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/users \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of users.

```
{
  "data": [
    {
      "id": 12,
      "name": "Alice Agent",
      "email": "alice@yourcompany.com",
      "role": "agent",
      "active": true,
      "group_ids": [
        3
      ],
      "created_at": "2025-11-03T16:20:00Z",
      "updated_at": "2026-01-12T08:02:11Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Get a user

GET `/api/v1/users/{id}`

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` required | path | integer | The user's id. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/users/12 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The user.

```
{
  "data": {
    "id": 12,
    "name": "Alice Agent",
    "email": "alice@yourcompany.com",
    "role": "agent",
    "active": true,
    "group_ids": [
      3
    ],
    "created_at": "2025-11-03T16:20:00Z",
    "updated_at": "2026-01-12T08:02:11Z"
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Groups

The teams tickets are routed to. Read-only.

### List groups

GET `/api/v1/groups`

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/groups \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of groups.

```
{
  "data": [
    {
      "id": 3,
      "name": "Billing",
      "description": "Invoices, refunds and payment questions",
      "user_ids": [
        12,
        15
      ],
      "created_at": "2025-11-03T16:20:00Z",
      "updated_at": "2025-11-03T16:20:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Get a group

GET `/api/v1/groups/{id}`

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` required | path | integer | The group's id. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/groups/3 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The group.

```
{
  "data": {
    "id": 3,
    "name": "Billing",
    "description": "Invoices, refunds and payment questions",
    "user_ids": [
      12,
      15
    ],
    "created_at": "2025-11-03T16:20:00Z",
    "updated_at": "2025-11-03T16:20:00Z"
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Macros

Saved replies. Read-only.

### List macros

GET `/api/v1/macros`

Saved replies, as written: `{{ customer_name }}`, `{{ agent_name }}` and `{{ ticket_number }}` are placeholders, filled in when an agent uses the macro.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/macros \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of macros.

```
{
  "data": [
    {
      "id": 7,
      "title": "Refund sent",
      "body": "Hi {{ customer_name }},\n\nYour refund is on its way.\n\n{{ agent_name }}",
      "created_at": "2025-12-01T10:00:00Z",
      "updated_at": "2025-12-01T10:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Records

Your own product's records about your customers (accounts, orders, subscriptions), pushed here so a ticket can show them. Needs the Production data capability. Addressed by a type of your choosing and your own id.

### List records

GET `/api/v1/records`

The records you have pushed, oldest first. Filter by the customer address they belong to, by type, or both.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `email` | query | string | Only records that belong to exactly this address. |
| `type` | query | string | Only records of this type. |
| `page` | query | integer | Which page, from 1. Default `1`. |
| `per_page` | query | integer | How many to a page. Default `25`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/records \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · A page of records.

```
{
  "data": [
    {
      "type": "account",
      "external_id": "381",
      "emails": [
        "carol@example.com"
      ],
      "title": "Carol Customer",
      "url": "https://admin.yourcompany.com/customers/381",
      "data": {
        "plan": "Team",
        "seats": 12,
        "renews_at": "2026-09-01T00:00:00Z"
      },
      "bytes": 137,
      "created_at": "2026-01-31T09:30:00Z",
      "updated_at": "2026-02-02T16:05:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 2,
    "next_page": null
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The Production data capability is switched off for this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Push many records

POST `/api/v1/records/batch`

Up to 500 upserts and deletes in one call. Each item stands alone: one that is refused says why in its own result and the rest still go through, so the answer is a `200` even when some items failed. An item with `"delete": true` removes that record and needs only `type` and `external_id`.

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `records` required | array of object | Up to 500 items. Each is a record to upsert (`type`, `external_id`, `emails`, and optionally `title`, `url`, `data`), or `type`, `external_id` and `"delete"` set to true. |

#### Example request

```
curl -X POST https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/records/batch \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "records": [
    {
      "type": "account",
      "external_id": "381",
      "emails": [
        "carol@example.com"
      ],
      "title": "Carol Customer",
      "url": "https://admin.yourcompany.com/customers/381",
      "data": {
        "plan": "Team",
        "seats": 12
      },
      "delete": false
    }
  ]
}'
```

#### Example response 200 · One result for each item, in the order they were sent.

```
{
  "data": [
    {
      "type": "account",
      "external_id": "381",
      "status": "created",
      "errors": null
    }
  ],
  "summary": {
    "created": 1
  }
}
```

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Get a record

GET `/api/v1/records/{record_type}/{external_id}`

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `record_type` required | path | string | What kind of record it is, in your own words. Letters, numbers, `_`, `-` and `:`. |
| `external_id` required | path | string | Your own id for the record. Letters, numbers and `. _ - :`. |

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/records/account/381 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The record.

```
{
  "data": {
    "type": "account",
    "external_id": "381",
    "emails": [
      "carol@example.com"
    ],
    "title": "Carol Customer",
    "url": "https://admin.yourcompany.com/customers/381",
    "data": {
      "plan": "Team",
      "seats": 12,
      "renews_at": "2026-09-01T00:00:00Z"
    },
    "bytes": 137,
    "created_at": "2026-01-31T09:30:00Z",
    "updated_at": "2026-02-02T16:05:00Z"
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The Production data capability is switched off for this workspace.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Create or replace a record

PUT `/api/v1/records/{record_type}/{external_id}`

The first `PUT` of a type and id creates the record; every later one replaces its addresses, title, link and data with what you send. A ticket from any address in `emails` shows the record.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `record_type` required | path | string | What kind of record it is, in your own words. Letters, numbers, `_`, `-` and `:`. |
| `external_id` required | path | string | Your own id for the record. Letters, numbers and `. _ - :`. |

#### Body

| Field | Type | Description |
| --- | --- | --- |
| `emails` required | array of string | 1 to 20 customer addresses the record belongs to. A ticket from any of them shows it. |
| `title` | string or null | What the card on a ticket is called. Up to 255 characters. |
| `url` | string or null | A link to the record in your own admin. `http` or `https` only. |
| `data` | object | What support should see, as a JSON object of up to 64KB. Shown on the ticket and given to AI drafts. |

#### Example request

```
curl -X PUT https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/records/account/381 \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "emails": [
    "carol@example.com"
  ],
  "title": "Carol Customer",
  "url": "https://admin.yourcompany.com/customers/381",
  "data": {
    "plan": "Team",
    "seats": 12,
    "renews_at": "2026-09-01T00:00:00Z"
  }
}'
```

#### Example response 200 · The record, replaced.

```
{
  "data": {
    "type": "account",
    "external_id": "381",
    "emails": [
      "carol@example.com"
    ],
    "title": "Carol Customer",
    "url": "https://admin.yourcompany.com/customers/381",
    "data": {
      "plan": "Team",
      "seats": 12,
      "renews_at": "2026-09-01T00:00:00Z"
    },
    "bytes": 137,
    "created_at": "2026-01-31T09:30:00Z",
    "updated_at": "2026-02-02T16:05:00Z"
  }
}
```

**201**: The record, created.

#### Errors

- **400** `bad_request`: A parameter is malformed, or the body is not valid JSON.
- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **422** `validation_failed`: The request was understood but a field is not acceptable. `details` says which.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

### Delete a record

DELETE `/api/v1/records/{record_type}/{external_id}`

Removes our copy. Pushing the same type and id again brings it back.

#### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `record_type` required | path | string | What kind of record it is, in your own words. Letters, numbers, `_`, `-` and `:`. |
| `external_id` required | path | string | Your own id for the record. Letters, numbers and `. _ - :`. |

#### Example request

```
curl -X DELETE https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/records/account/381 \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · The record that was deleted.

```
{
  "data": {
    "type": "account",
    "external_id": "381",
    "deleted": true
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **403** `forbidden`: The token is read-only, or acts as somebody with a read-only seat.
- **404** `not_found`: Nothing with that number or id in this workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.

## Account

What the token you are using is.

### Get the token's identity

GET `/api/v1/me`

The user the token acts as, the workspace it belongs to and what it may do. The quickest way to check a token works.

#### Example request

```
curl https://YOUR-WORKSPACE.lagottolabs.ai/api/v1/me \
  -H "Authorization: Bearer $API_TOKEN"
```

#### Example response 200 · Who the token is.

```
{
  "data": {
    "user": {
      "id": 12,
      "name": "Alice Agent",
      "email": "alice@yourcompany.com",
      "role": "agent",
      "active": true,
      "group_ids": [
        3
      ],
      "created_at": "2025-11-03T16:20:00Z",
      "updated_at": "2026-01-12T08:02:11Z"
    },
    "workspace": {
      "name": "Your Company",
      "subdomain": "your-workspace",
      "time_zone": "UTC"
    },
    "access": "write"
  }
}
```

#### Errors

- **401** `unauthorized`: The token is missing, wrong, revoked, expired, or belongs to another workspace.
- **429** `rate_limited`: Too many requests from this token. `Retry-After` says how many seconds to wait.
