# Conventions

> The rules every endpoint follows - the response envelope, the queryselector segment of reads, pagination, writes and deletes, ids, timestamps and organization scope.

Source: https://docs.sommatic.ai/en/api/conventions/ (updated 2026-11-26)

Learn these rules once and every group of the API reads the same way: how a response is wrapped, how to ask for one
record or a page of them, how to write, and how your organization limits what you see.

## The envelope

Every JSON response, success or failure, has the same four fields:

```json
{
  "status": 200,
  "success": true,
  "message": "Operation completed successfully",
  "result": {}
}
```

| Field     | Meaning                                                                         |
| --------- | ------------------------------------------------------------------------------- |
| `status`  | The HTTP status code, repeated in the body.                                     |
| `success` | `true` when the operation did what you asked. Check it before reading `result`. |
| `message` | A human-readable summary; on failure, the reason.                               |
| `result`  | The data: a record, a page of records, or `null` on failure.                    |

## Reads: the `:queryselector` segment

Reads are `GET` requests whose last path segment says **how** you are asking. The value you search for goes in the
`search` query parameter:

| Selector          | Returns                                                     | Example                                                                               |
| ----------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| `id`              | The record with that id.                                    | `GET /work-management/task/id?search=task-…`                                          |
| `organization-id` | The records of one organization, paginated.                 | `GET /project/management/organization-id?search=<organization id>&page=1&pageSize=25` |
| `all`             | Every record you can see, paginated and filtered by status. | `GET /workflow-orchestration/control-plane/flow-design/flow-definition/all?page=2`    |

Some resources add their own selectors, for example `flow-definition-id` on flow versions, `inbox` on tasks or
`statuses` on several resources, which returns the statuses a record can have. Each endpoint of the
[API reference](https://docs.sommatic.ai/en/api/reference/workflow-design.md) lists the selectors it accepts. An unknown selector fails with
"Provide a valid slug to query".

Filter by status with `include_status` and `exclude_status`, each a comma-separated list of status names, for example
`exclude_status=deleted`.

> **Tip: Even one record comes in a list**
>
> A read by `id` returns `result.items` with one element, like any other read. Take the first item instead of
> expecting the record at the top of `result`.

## Pagination

Paginated reads take `page` (from 1) and `pageSize` (25 by default) and answer:

```json
{
  "items": [],
  "totalItems": 42,
  "totalPages": 2,
  "currentPage": 1,
  "pageSize": 25
}
```

Request the next page until `currentPage` equals `totalPages`.

## Writes

| Operation | Request              | Body                                          |
| --------- | -------------------- | --------------------------------------------- |
| Create    | `POST <resource>/`   | The new record. Sommatic AI assigns the `id`. |
| Update    | `PATCH <resource>/`  | The `id` and the fields to change.            |
| Delete    | `DELETE <resource>/` | `{ "id": "…" }`                               |

A delete changes the record's status to `deleted` instead of erasing it, so its history and the runs that used it stay
traceable. Reads still return deleted records unless you pass `exclude_status=deleted`.

Actions that are not plain edits have their own path, for example
`POST /workflow-orchestration/control-plane/flow-design/flow-definition/:id/publish` or
`PATCH /work-management/task/transition/`.

## Ids and timestamps

- **Ids** are strings generated by Sommatic AI with a prefix that names the entity: `task-…`, `wf-flow-definition-…`.
  Treat them as opaque: store and send them back as they are, never build them.
- **Timestamps** are Unix epoch milliseconds written as strings, such as `"1761830100000"`. Records carry
  `created.timestamp` and `modified.timestamp`.
- **Status** is an object, not a string: `{ "name": "active", "title": "Active", … }`. Filters use its `name`.

## Organization scope

Everything in Sommatic AI belongs to an organization, and your token is issued for one. Send `organization_id` in the body
of what you create, and read with the `organization-id` selector (or the `organization_id` parameter where an endpoint
asks for it) so you only get your organization's records.

## Next steps

- [Errors](https://docs.sommatic.ai/en/api/errors.md): What a failure looks like and how to react to it.
- [Workflow design endpoints](https://docs.sommatic.ai/en/api/reference/workflow-design.md): Apply these conventions to flow definitions and versions.
