# Hoteza API (https://docs.treema.online/en/docs/settings/task-integrations-api)

For Hoteza's developers — the contract for creating tasks in a connected property with an API key, the request and response format, errors, limits and status callbacks.

This page is the API contract for **Hoteza**, connected through
[Task integrations](https://docs.treema.online/en/docs/settings/integrations/). It is for Hoteza's developers: how to create
tasks and how Treema HQ reports their status changes back.

## Base URL and authentication [#base-url-and-authentication]

All requests go to `https://external.treema.ai`.

Each connected property has its own API key, and the key alone identifies the property. Send it in
the `X-Auth-Token` header; `Authorization: Bearer <api key>` is accepted too. A missing or wrong key,
a key that has been replaced, and the key of a deleted connection all get `401 INVALID_TOKEN`.

## Create a task [#create-a-task]

`POST /v1/external/tasks` with a JSON body of at most 64 KB.

```bash
curl -X POST "https://external.treema.ai/v1/external/tasks" \
  -H "Content-Type: application/json" \
  -H "X-Auth-Token: $API_KEY" \
  -d '{
    "id": "req-10452",
    "createdAt": "2026-11-09T08:15:00Z",
    "text": "Extra towels",
    "room": "412",
    "description": "Two bath towels, please."
  }'
```

| Field         | Type   | Required | Limits                         | Meaning                                                                                                                                                                                                                                                                                          |
| ------------- | ------ | -------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`          | string | yes      | 1–64 characters                | Your request id. A repeat for the same connection creates nothing (see `DUPLICATE` below).                                                                                                                                                                                                       |
| `createdAt`   | string | yes      | 1–32 characters                | Your request time, stored as sent.                                                                                                                                                                                                                                                               |
| `text`        | string | yes      | 1–512 characters               | The service requested. It selects the task template with the same **name**, ignoring case and surrounding spaces: the property's own template first, then one shared across the workspace. With no match, the task takes this text as its title and goes to the connection's default department. |
| `room`        | string | yes      | 0–256 characters, may be empty | The room's name, matched exactly. A room that matches none is added to the description as `Room: <value>`.                                                                                                                                                                                       |
| `description` | string | no       | 0–10 000 characters            | Shown to staff as sent, line breaks kept. Replaces the template's description.                                                                                                                                                                                                                   |

Unknown fields are ignored, so `hotelKey` and `assigneeEmails` from older clients do no harm.

## Responses [#responses]

Every response is JSON. A created task:

```json
{ "error": 0, "data": { "id": "req-10452", "taskId": "6730c1f2a4b5c6d7e8f90123" } }
```

An error carries a code and a message:

```json
{ "error": 1, "code": "INVALID_BODY", "msg": "text: Too small: expected string to have >=1 characters" }
```

| Status | `code`                  | When                                                                                                                                      |
| ------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| 200    | —                       | The task was created.                                                                                                                     |
| 409    | `DUPLICATE`             | A task with this `id` already exists for the connection. `data` holds its `id` and `taskId`; `msg` is *Task with this ID already exists*. |
| 400    | `INVALID_BODY`          | The body is not valid JSON or a field breaks the rules above. `msg` names the first bad field.                                            |
| 401    | `INVALID_TOKEN`         | The API key is missing or invalid.                                                                                                        |
| 403    | `INTEGRATION_PAUSED`    | The property's administrator paused the connection.                                                                                       |
| 403    | `INTEGRATIONS_DISABLED` | Task integrations are turned off for the workspace.                                                                                       |
| 413    | `PAYLOAD_TOO_LARGE`     | The body is larger than 64 KB.                                                                                                            |
| 429    | `RATE_LIMITED`          | Too many requests (see Limits).                                                                                                           |
| 500    | `INTERNAL_ERROR`        | Something failed on our side.                                                                                                             |

Retry a 5xx, a network error or a timeout with the same `id`: if the first attempt did create the
task, the retry gets `409 DUPLICATE` with its ids instead of a second task.

## Limits [#limits]

Each API key may send 120 requests a minute, and each client IP address 300. Over either limit the
request gets `429 RATE_LIMITED`. Treat `429` and `503` as "retry later", with a pause that grows
between attempts.

## Status callbacks [#status-callbacks]

If the connection has a callback url, Treema HQ sends every status change of a task
created through it to that address. The callback url and its authorization token come from you and
are entered by the property's administrator when connecting.

```http
POST <your callback url>
Content-Type: application/json
authorization: <your token>

{ "id": "req-10452", "newTaskStatus": 2, "newTaskStatusName": "INPROGRESS", "changedAt": "2026-11-09T08:21:37.512Z" }
```

`id` is the request id you sent when creating the task. `changedAt` is the time of the change in
ISO 8601.

| Status in Treema HQ | `newTaskStatus` | `newTaskStatusName` |
| ------------------- | --------------- | ------------------- |
| To do               | 1               | `NEW`               |
| In progress         | 2               | `INPROGRESS`        |
| Done                | 3               | `DONE`              |
| Paused              | 4               | `PAUSED`            |
| Cancelled           | 5               | `CANCELED`          |
| Accepted            | 6               | `ACCEPTED`          |

* **Your answer.** Any 2xx within 10 seconds counts as delivered. Redirects are not followed. The
  address must use `https` on the default port and resolve to a public address.
* **Retries.** A failed delivery is retried after 30 seconds, then 1, 2, 5, 10, 15, 30 and 30
  minutes, about an hour and a half in all. After that it is given up, and the connection shows as
  failing to the property's administrator.
* **Order.** Once a newer status of the same task exists, older undelivered ones are dropped. Use
  `changedAt` to ignore a status older than one you already have.
* **Pauses.** Nothing is sent while the connection is paused or deleted, or while task integrations
  are turned off for the workspace, and changes from that time are not sent later.
