# Integrations API (CRM, ERP, KPI)

> API endpoints made for other systems such as a CRM, an ERP or a KPI tool — create a task by project key and names, link tasks to records in your system and find them again, and export KPIs per person — with the tokens, limits and errors involved.

Source: https://docs.sofiaspace.uz/api/integrations/

Your other systems — an ERP such as 1C, a CRM such as Bitrix24 or amoCRM, a KPI or payroll tool — know their own records, not Sofia Space IDs. These endpoints let them work in their own terms: create a task in project `WEB` assigned to `ali.valiyev@example.com`, mark it as belonging to ERP order `ORD-2026-0815`, find that task again from the order, and pull each person's KPIs for the month.

**Who this is for:** developers connecting a company system to Sofia Space. **Plan:** every plan includes integration accounts.

## Which token to use

Use an **integration account** token. An integration account is a workspace member that is a system, not a person: it doesn't use a seat, can't sign in to the app, keeps working when the admin who made it leaves, and shows its own name with an **Integration** badge on everything it does.

**Who can create one:** Org Admins, in **Settings → Integrations → Integration accounts**. They pick the account's role, add it to the projects it works in, and create its token with the scopes it needs. Step by step: [Integration accounts](https://docs.sofiaspace.uz/integrations/integration-accounts.md).

The scopes these endpoints need, with their names in the token dialog:

| Scope | Shown as | Needed for |
| --- | --- | --- |
| `tasks:write` | **Create and update tasks and comments** | Creating tasks, linking and unlinking records |
| `tasks:read` | **Projects and tasks** | Finding a task by a record |
| `dashboards:read` | **Dashboards and reports** | The KPI export and the timesheet |

A [personal API token](https://docs.sofiaspace.uz/integrations/api-tokens.md) with the same scopes works too, but it acts as you, stops working if you leave, and follows the workspace's rules for AI apps. An integration account's token doesn't: switching **AI agents** off or allowing only approved AI apps doesn't cut it off. Its scopes and its role still apply.

Send the token as `Authorization: Bearer sophie_pat_…` on your workspace's own address. Examples use `acme.sofiaspace.uz`, organization ID `6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20` (from [your workspace](https://docs.sofiaspace.uz/api/me-and-workspace.md)) and the project `WEB`.

## Create a task by project key

`POST /api/v1/orgs/{orgId}/projects/by-key/{projectKey}/tasks` — **Scope:** `tasks:write`. Honours [`Idempotency-Key`](https://docs.sofiaspace.uz/api/idempotency.md). Counts against the same task-create cap as the other create route: 120 tasks a minute per token owner, both routes together (see [Rate limits](https://docs.sofiaspace.uz/api/rate-limits.md#per-action-caps)).

Like [Create a task](https://docs.sofiaspace.uz/api/tasks.md#create-a-task), but with names instead of IDs: the project by its key, the type and status by name, people by e-mail.

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `title` | string | yes | Up to 500 characters |
| `type` | string | no | A task type's name or ID, for example `Bug`. Default: **Task**, or the workspace's first type if it has no **Task** |
| `status` | string | no | A status name or ID of this project. Default: the first status |
| `assignee` | string | no | A member's user ID, or their e-mail. An e-mail must be an active member's whole e-mail address (any case); part of an address never matches |
| `reporter` | string | no | Same; default is the token's account |
| `priority` | string | no | `HIGHEST`, `HIGH`, `MEDIUM` (default), `LOW` or `LOWEST`, any case |
| `description` | string | no | Plain text or a rich-text document string |
| `storyPoints` | integer | no | 0 to 1,000 |
| `dueDate`, `startDate` | string | no | `yyyy-MM-dd`; the start can't be after the due date |
| `fieldValues` | object[] | no | Custom-field values, as in [Set custom-field values](https://docs.sofiaspace.uz/api/tasks.md#set-custom-field-values) |
| `externalRef` | object | no | The record this task is for: `system`, `id`, optional `url` and `label`. See [Create without duplicates](#create-without-duplicates) |

The project key and the names match without regard to case. The project must be one the token's account can open: add the integration account to the project first.

Example — the ERP opens a task in `WEB` for a new order:

```bash
curl -X POST https://acme.sofiaspace.uz/api/v1/orgs/6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20/projects/by-key/WEB/tasks \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Deliver website for order ORD-2026-0815",
    "type": "Task",
    "status": "To Do",
    "assignee": "ali.valiyev@example.com",
    "priority": "high",
    "dueDate": "2026-12-15",
    "externalRef": {
      "system": "erp",
      "id": "ORD-2026-0815",
      "url": "https://erp.example.uz/orders/ORD-2026-0815",
      "label": "Order ORD-2026-0815"
    }
  }'
```

Answer — `201` and the [task](https://docs.sofiaspace.uz/api/tasks.md#the-task-object), here shortened:

```json
{
  "id": "3b5d7f91-2c4e-4a6b-8d0f-1e3a5c7b9d24",
  "projectId": "a4c6e8f0-1b3d-4f5a-9c7e-2d4f6b8a0c13",
  "taskNumber": 87,
  "statusId": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
  "title": "Deliver website for order ORD-2026-0815",
  "assigneeId": "5e7a9c1b-3d5f-4b7a-9c2e-4f6a8b0d2c46",
  "priority": "HIGH",
  "dueDate": "2026-12-15",
  "externalRefs": [
    {
      "system": "erp",
      "id": "ORD-2026-0815",
      "url": "https://erp.example.uz/orders/ORD-2026-0815",
      "label": "Order ORD-2026-0815",
      "createdBy": "0f2e4d6c-8b1a-4c3e-9d5f-7a9b1c3d5e60",
      "createdAt": "2026-11-25T08:30:00Z"
    }
  ]
}
```

The task's key is the project key and `taskNumber`: `WEB-87`.

Errors:

| Status | `code` | Why |
| --- | --- | --- |
| `400` | `MEMBER_EMAIL_NOT_FOUND` | No active member has exactly that e-mail. `params.field` is `assignee` or `reporter` |
| `400` | `MEMBER_EMAIL_AMBIGUOUS` | The e-mail matched too many members (20 or more) to find the exact one: "Too many members match the e-mail given as assignee; pass their user id instead". Send the person's user ID ([find it](https://docs.sofiaspace.uz/api/me-and-workspace.md#find-members-by-name-or-e-mail)). `params.field` is `assignee` or `reporter` |
| `400` | `STORY_POINTS_TOO_HIGH`, `NAME_REQUIRED` | `storyPoints` above 1,000 (`params.max`), or a blank `title` |
| `400` | `INVALID_ARGUMENT` | `Unknown task type: …`, `Unknown status in this project: …`, or another invalid field, as for [Create a task](https://docs.sofiaspace.uz/api/tasks.md#create-a-task) |
| `403` | `PERMISSION_DENIED` | The account may not create tasks in this project |
| `404` | `NOT_FOUND` | No project with that key that the account can open |
| `409` | `EXTERNAL_REF_TAKEN` | The `externalRef` is already linked to a task the account can't open (`params.system`, `params.externalId`) |
| `429` | `RATE_LIMITED` | More than 120 tasks created in a minute (by-key and by-ID creates together) |

You can't set labels, a parent, an epic, a sprint or a team here. Use [Create a task](https://docs.sofiaspace.uz/api/tasks.md#create-a-task) with IDs for those, or change the task afterwards.

## Create without duplicates

A create that carries an `externalRef` is safe to retry, on this endpoint and on [`POST /api/v1/projects/{projectId}/tasks`](https://docs.sofiaspace.uz/api/tasks.md#create-a-task):

- If no task holds that record yet, the task is created with the link — `201`.
- If a task the account can open already holds it, nothing is created: you get **that** task with `200` and the header `X-Sofia-Existing: true`.
- If a task the account can't open holds it, the create is refused with `409`.
- The task, its field values and its link are saved together: a bad field value or link refuses the whole create, and no task is left behind.

Two creates for the same record at the same moment don't both succeed: one creates, the other gets the existing task.

Both create routes also honour [`Idempotency-Key`](https://docs.sofiaspace.uz/api/idempotency.md): a retry with the same key within 10 minutes gets the first answer back. Use it for creates that carry no `externalRef`; with an `externalRef`, the record itself already makes the retry safe, for good.

## Link a task to a record in your system

`PUT /api/v1/tasks/{taskId}/external-refs/{system}/{id}` — **Scope:** `tasks:write`, and the right to edit the task.

Adds the link, or updates its `url` and `label` if the task already has it. Body (optional): `{"url": "…", "label": "…"}`. Returns `200` and the task, with `externalRefs` filled.

```bash
curl -X PUT https://acme.sofiaspace.uz/api/v1/tasks/3b5d7f91-2c4e-4a6b-8d0f-1e3a5c7b9d24/external-refs/crm/4512 \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://crm.example.uz/deals/4512","label":"Deal #4512"}'
```

| Part | Rules |
| --- | --- |
| `system` | 1–40 characters: lower-case letters, digits, `-` and `_`, starting with a letter or digit. A short name for your system, such as `erp`, `1c`, `crm`, `bitrix24` |
| `id` | The record's ID in that system, 1–200 characters. URL-encode it in the path |
| `url` | Optional; an `http` or `https` link, up to 2,000 characters |
| `label` | Optional; up to 200 characters, shown on the task, for example `Deal #4512` |

One record links to **one** task in the workspace; a task can hold up to 20 links. People see the links on the task under **Linked records**, and can add or remove them there too.

Errors:

| Status | `code` | Why |
| --- | --- | --- |
| `400` | `INVALID_ARGUMENT` | A `system`, `id`, `url` or `label` that breaks the rules |
| `404` | `NOT_FOUND` | No such task, or you can't open it |
| `409` | `EXTERNAL_REF_TAKEN` | The record is already linked to another task (`params.system`, `params.externalId`) |
| `409` | `EXTERNAL_REF_LIMIT` | The task already holds 20 links (`params.max`) |

## Remove a link

`DELETE /api/v1/tasks/{taskId}/external-refs/{system}/{id}` — **Scope:** `tasks:write`. Returns `200` and the task. Removing a link the task doesn't have changes nothing and still answers `200`. The task and the record stay; only the link goes.

## Find the task for a record

`GET /api/v1/orgs/{orgId}/tasks/by-external-ref?system={system}&id={id}` — **Scope:** `tasks:read`.

Returns the [task](https://docs.sofiaspace.uz/api/tasks.md#the-task-object) linked to that record, with `externalRefs` filled. `404 NOT_FOUND` when no task holds it **or** the account can't open the task that does.

```bash
curl -G https://acme.sofiaspace.uz/api/v1/orgs/6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20/tasks/by-external-ref \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  --data-urlencode "system=erp" \
  --data-urlencode "id=ORD-2026-0815"
```

Use it to sync back: when the order ships, find its task and [move it to Done](https://docs.sofiaspace.uz/api/tasks.md#move-a-task-to-another-status).

## Export KPIs per person

`GET /api/v1/orgs/{orgId}/kpi` — **Scope:** `dashboards:read`.

Per person over a date range, optionally split by month or week: tasks completed, points, on-time rate, open and overdue tasks, median cycle time and hours logged. These are the same numbers the dashboards show.

| Parameter | Meaning |
| --- | --- |
| `from`, `to` | Days, `yyyy-MM-dd`, inclusive. Default: the last 30 days up to today. At most 731 days |
| `groupBy` | `none` (default, one block for the whole range), `month` or `week` (Monday to Sunday). At most 60 periods |
| `tz` | Time zone the days are counted in, for example `Asia/Tashkent`; default UTC |
| `userIds`, `projectIds`, `teamIds` | Only these people, projects or teams (repeat a parameter for several) |
| `format` | `json` (default) or `csv` |

```bash
curl -G https://acme.sofiaspace.uz/api/v1/orgs/6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20/kpi \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  --data-urlencode "from=2026-10-01" \
  --data-urlencode "to=2026-10-31" \
  --data-urlencode "tz=Asia/Tashkent"
```

```json
{
  "from": "2026-10-01",
  "to": "2026-10-31",
  "groupBy": "none",
  "timeTracked": true,
  "notices": [],
  "rows": [
    {
      "periodStart": "2026-10-01",
      "periodEnd": "2026-10-31",
      "userId": "5e7a9c1b-3d5f-4b7a-9c2e-4f6a8b0d2c46",
      "name": "Ali Valiyev",
      "email": "ali.valiyev@example.com",
      "completedTasks": 18,
      "completedPoints": 34,
      "completedWithDueDate": 15,
      "completedOnTime": 13,
      "onTimeRate": 0.8667,
      "openTasks": 6,
      "overdue": 1,
      "medianCycleDays": 2.5,
      "hoursLogged": 96.5
    }
  ]
}
```

| Field | Meaning |
| --- | --- |
| `completedTasks`, `completedPoints` | Tasks the person finished in the period, and their story points |
| `completedWithDueDate`, `completedOnTime`, `onTimeRate` | Of those, how many had a due date, how many were finished on or before it, and the share (`0` to `1`; `null` when none had a due date) |
| `openTasks`, `overdue` | Unfinished tasks assigned to the person **now**, and how many are past due — the same in every period |
| `medianCycleDays` | Median days from start to finish |
| `hoursLogged` | Hours logged in the period; `null` when no project in scope tracks time (`timeTracked: false`) |
| `email` | `null` for an integration account |
| `notices` | Hints about the numbers, for example `people_restricted` (you only see your own row) or `tracking_off_all` (no project tracks time) |

Rows are ordered by tasks completed, most first; with `groupBy` there's one row per person per period.

**Whose numbers you get:** everyone's needs Org Admin, Project Admin or a role with **See people analytics** in the projects counted. Without it, only the token account's own row comes back (with the notice `people_restricted`), and asking for other `userIds` is refused with `403`. Give the integration account a role with **See people analytics** if your KPI tool needs everyone.

**CSV:** `format=csv` answers a UTF-8 file named `kpi-<from>-<to>.csv` with the same columns. It starts with a byte-order mark, so Excel shows Cyrillic and Uzbek letters correctly.

Errors: `400` for a date not `yyyy-MM-dd`, `from` after `to` (`DATE_RANGE_INVALID`), more than 731 days, more than 60 periods, or an unknown `groupBy`; `403` for other people's numbers without the right.

For hours per person, task and day — for payroll or billing — use the [timesheet](https://docs.sofiaspace.uz/api/time-tracking.md#read-a-timesheet).

## Limits

| What | Limit |
| --- | --- |
| Integration accounts in a workspace | 50 |
| [Webhooks](https://docs.sofiaspace.uz/integrations/webhooks.md) in a workspace | 25 |
| Links (external references) on one task | 20 |
| One record | Linked to one task in the workspace |
| `system` / `id` / `url` / `label` | 40 / 200 / 2,000 / 200 characters |
| KPI range | 731 days, 60 periods per request |
| Timesheet range | 93 days |

An integration account's tokens may make **300 requests per minute**, counted per account across all its tokens and the same on every plan — the same limit as a personal token with these scopes, not the workspace's shared 600 for script tokens. See [Rate limits](https://docs.sofiaspace.uz/api/rate-limits.md).

## Get events instead of polling

To hear about changes without polling, an Org Admin adds a [webhook](https://docs.sofiaspace.uz/integrations/webhooks.md) for the integration account in **Settings → Integrations**. Each event carries a full task snapshot, including `startedAt` and `completedAt`.

## What you can't do

- You can't set up [webhooks](https://docs.sofiaspace.uz/integrations/webhooks.md) through the API; an Org Admin adds them in **Settings → Integrations**.
- There are no ready-made connectors for 1C, Bitrix24 or amoCRM yet; connect them through these endpoints.
- You can't create integration accounts or their tokens through the API; an Org Admin does it in **Settings → Integrations**.
- You can't list every task linked to records of one system, or search by a record's label; look up one record at a time.
- You can't set labels, a parent, an epic, a sprint or a team when creating by project key.

## Related

- [Integration accounts](https://docs.sofiaspace.uz/integrations/integration-accounts.md) — create the account and its token
- [Tasks](https://docs.sofiaspace.uz/api/tasks.md)
- [Time tracking](https://docs.sofiaspace.uz/api/time-tracking.md) — worklogs and the timesheet
- [Authentication and scopes](https://docs.sofiaspace.uz/api/authentication.md)
- [Errors](https://docs.sofiaspace.uz/api/errors.md)
