# Time tracking (API)

> API endpoints to read the time logged on a task, log and edit work (for example from a timesheet or ERP), run the timer, set a task's original and remaining estimate, and read a timesheet across tasks and people.

Source: https://docs.sofiaspace.uz/api/time-tracking/

When **Time tracking** is on for a project, people log the time they spent on tasks (**worklogs**) and keep an **estimate** of what's left. The API lets you read a task's time, log and correct work from another system — a timesheet app, an ERP that bills hours — start and stop your own timer, set estimates, and read a timesheet of everyone's hours for payroll or billing.

**Scope:** reading a task's time and your timer needs `tasks:read`; logging, editing worklogs, the timer and estimating need `tasks:write`; the timesheet needs `dashboards:read`. Time tracking must be switched on for the project (it's off by default on new projects; a project admin turns it on — see [Time tracking](https://docs.sofiaspace.uz/tasks/time-tracking.md)). If it's off, writes fail with `409 FAILED_PRECONDITION` ("Time tracking is off for this project").

## Read a task's time

`GET /api/v1/tasks/{taskId}/time` — **Scope:** `tasks:read`.

```bash
curl https://acme.sofiaspace.uz/api/v1/tasks/7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20/time \
  -H "Authorization: Bearer $SOFIA_TOKEN"
```

```json
{
  "taskId": "7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20",
  "enabled": true,
  "settings": {},
  "originalMinutes": 480,
  "remainingMinutes": 210,
  "spentMinutes": 270,
  "worklogs": [
    {
      "id": "a7b8c9d0-1e2f-4a3b-8c4d-5e6f7a8b9c0d",
      "taskId": "7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20",
      "projectId": "9d2e7a10-4b6c-4e8f-a1d3-5c7e9b2f4a68",
      "userId": "8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62",
      "startedAt": "2026-11-13T05:00:00Z",
      "minutes": 150,
      "description": "Account set-up",
      "source": "MANUAL",
      "createdBy": "8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62",
      "createdAt": "2026-11-13T07:31:00Z"
    }
  ],
  "canLogForOthers": false,
  "canManageWorklogs": false
}
```

| Field | Meaning |
| --- | --- |
| `enabled` | Whether time tracking is on for the task's project |
| `settings` | The project's time-tracking rules, for example whether it uses estimates, whether a worklog needs a description, and who may log for others |
| `originalMinutes`, `remainingMinutes` | The estimate; `null` when not set |
| `spentMinutes` | Total of all worklogs |
| `canLogForOthers` | You may log time for other people on this project |
| `canManageWorklogs` | You may change other people's worklogs (in the app) |

## Log work

`POST /api/v1/tasks/{taskId}/worklogs` — **Scope:** `tasks:write`. Returns `200` and the new worklog.

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `startedAt` | string | yes | When the work happened, an ISO time such as `2026-11-14T05:00:00Z` |
| `minutes` | integer | yes | 1 to 1,440 (24 hours) |
| `description` | string | depends | What was done, up to 2,000 characters; some projects require it |
| `remainingMode` | string | no | `AUTO` (default: lower the remaining estimate by `minutes`), `SET` (set it to `remainingMinutes`) or `LEAVE` (don't touch it) |
| `remainingMinutes` | integer | with `SET` | The new remaining estimate |
| `userId` | string | no | Log for another member (needs `canLogForOthers`: the project lets managers log for others, and you're a Project Admin or hold the worklog-manage permission); default is you |

Example — your timesheet system reports 2 h 30 min for Malika on 14 November:

```bash
curl -X POST https://acme.sofiaspace.uz/api/v1/tasks/7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20/worklogs \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"startedAt":"2026-11-14T05:00:00Z","minutes":150,"description":"Training session","userId":"8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62"}'
```

Errors:

| Status | `code` | Why |
| --- | --- | --- |
| `400` | `WORKLOG_DATE_REQUIRED` | `startedAt` is missing |
| `400` | `WORKLOG_DURATION_INVALID` | `minutes` isn't 1 to 1,440 |
| `400` | `WORKLOG_DESCRIPTION_REQUIRED`, `WORKLOG_FUTURE_NOT_ALLOWED`, `WORKLOG_DONE_NOT_ALLOWED` | The project's rules: a description is required, no time in the future, or no time on finished tasks |
| `400` | `INVALID_ARGUMENT` | `remainingMode: "SET"` without `remainingMinutes`, a description over 2,000 characters, or a `userId` who isn't a member |
| `403` | `PERMISSION_DENIED` | Logging for someone else without the right |
| `409` | `FAILED_PRECONDITION` | Time tracking is off for the project |

Logging work is **not** idempotent: a retried request logs the time twice. Keep the worklog `id` you get back next to your timesheet row.

## Edit a worklog

`PATCH /api/v1/worklogs/{worklogId}` — **Scope:** `tasks:write`. Returns `200` and the changed worklog.

Only the person who logged the time can change it — or, for anyone's worklog, a Project Admin or a role with the worklog-manage permission (`canManageWorklogs` on the task's time). The project's time-tracking rules apply as when logging.

Send the worklog's new values; all three are written:

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `startedAt` | string | yes | When the work happened, an ISO time |
| `minutes` | integer | yes | 1 to 1,440 |
| `description` | string | no | Up to 2,000 characters. **Leaving it out removes the description** — send the old one to keep it |

The person, the task and the remaining estimate don't change.

```bash
curl -X PATCH https://acme.sofiaspace.uz/api/v1/worklogs/a7b8c9d0-1e2f-4a3b-8c4d-5e6f7a8b9c0d \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"startedAt":"2026-11-13T05:00:00Z","minutes":120,"description":"Account set-up"}'
```

Errors:

| Status | `code` | Why |
| --- | --- | --- |
| `400` | `WORKLOG_DATE_REQUIRED`, `WORKLOG_DURATION_INVALID` | `startedAt` is missing; `minutes` isn't 1 to 1,440 (also when it is left out) |
| `400` | `WORKLOG_DESCRIPTION_REQUIRED`, `WORKLOG_FUTURE_NOT_ALLOWED`, `WORKLOG_DONE_NOT_ALLOWED` | The project's rules |
| `400` | `INVALID_ARGUMENT` | A description over 2,000 characters |
| `403` | `PERMISSION_DENIED` | Someone else's worklog, and you can't manage worklogs in this project |
| `404` | `NOT_FOUND` | No such worklog, or you can't open its project |
| `409` | `FAILED_PRECONDITION` | Time tracking is off for the project |

Deleting a worklog isn't possible with a token: `DELETE /api/v1/worklogs/{worklogId}` answers `403` with `"error": "SIGNED_IN_APP_ONLY"`. To cancel time, edit the worklog, or delete it in the app.

## Use the timer

The timer is the token owner's own stopwatch, the same one as in the app: start it on a task, stop it, and the time is logged as a worklog. Each person has **one** timer. The project must have time tracking on and use the timer (see [Time tracking](https://docs.sofiaspace.uz/tasks/time-tracking.md)).

### Start the timer on a task

`POST /api/v1/tasks/{taskId}/timer` — **Scope:** `tasks:write`. No body. Returns the running timer.

```bash
curl -X POST https://acme.sofiaspace.uz/api/v1/tasks/7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20/timer \
  -H "Authorization: Bearer $SOFIA_TOKEN"
```

```json
{
  "taskId": "7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20",
  "projectId": "9d2e7a10-4b6c-4e8f-a1d3-5c7e9b2f4a68",
  "projectKey": "SALES",
  "taskNumber": 42,
  "taskTitle": "Onboard new customer (deal #1042)",
  "startedAt": "2026-11-14T05:00:00Z",
  "needsConfirmation": false
}
```

- If your timer already runs on **another** task, that time is logged first (as when you stop it), then the timer starts on this task. If the other task can't take the time any more (for example time tracking was switched off there), the old timer is dropped without logging.
- If it already runs on **this** task, it keeps running from its original start.

Errors: `409 FAILED_PRECONDITION` when time tracking is off for the project ("Time tracking is off for this project") or the project doesn't use the timer ("This project doesn't use the timer — log time instead"); `403` / `404` when you can't open the task.

### See your running timer

`GET /api/v1/me/timer` — **Scope:** `tasks:read`. Returns `{"timer": { … }}` in the shape above, or `{"timer": null}` when nothing runs.

`needsConfirmation` is `true` once the timer has run for more than 12 hours: the app then asks how long you really worked before logging. Send that duration as `minutes` when you stop it.

### Stop the timer and log the time

`POST /api/v1/me/timer/stop` — **Scope:** `tasks:write`. Returns `{"worklog": { … }}` with the new worklog, or `{"worklog": null}` when nothing was logged.

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `minutes` | integer | no | The time to log instead of the time measured. More than 1,440 is cut to 1,440; less than 1 logs nothing |
| `description` | string | depends | What was done; required when the project asks for a description |

The body is optional. Without `minutes`, the measured time is logged, at most 24 hours and rounded as the project's settings say. The worklog has `"source": "TIMER"` and lowers the remaining estimate like an `AUTO` log.

```bash
curl -X POST https://acme.sofiaspace.uz/api/v1/me/timer/stop \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"description":"Account set-up"}'
```

- `worklog` is `null` when no timer was running, when less than a minute was measured, or when the task was deleted while the timer ran. The timer is stopped either way.
- The project's rules apply as for [Log work](#log-work), with the same error codes. A refused stop leaves the timer running, so you can fix the request (for example add a description) and stop it again.

### Discard the timer

`DELETE /api/v1/me/timer` — **Scope:** `tasks:write`. Stops your timer **without** logging anything. `204`, also when no timer was running.

## Set the estimate

`PUT /api/v1/tasks/{taskId}/estimate` — **Scope:** `tasks:write`. Returns the task's time (same shape as above). Anyone who can open the task may estimate it.

Send what changes; a field you leave out keeps its value:

| Field | Type | Meaning |
| --- | --- | --- |
| `originalMinutes` | integer or `null` | The original estimate, 0 to 100,000 minutes |
| `clearOriginal` | boolean | `true` removes the original estimate (default `false`) |
| `remainingMinutes` | integer or `null` | Time still needed, 0 to 100,000 minutes. Ignored when the project doesn't track a remaining estimate |
| `clearRemaining` | boolean | `true` removes the remaining estimate (default `false`) |

```bash
curl -X PUT https://acme.sofiaspace.uz/api/v1/tasks/7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20/estimate \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"originalMinutes":480,"clearOriginal":false,"remainingMinutes":240,"clearRemaining":false}'
```

A missing or `null` minutes value with its clear flag `false` leaves that estimate as it is.

Errors: `400 INVALID_ARGUMENT` for minutes outside 0–100,000; `409 FAILED_PRECONDITION` when time tracking is off, or the project tracks time without estimates.

## Read a timesheet

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

Minutes logged per person, task and day, across every project you can open — what a payroll or billing system needs.

| Parameter | Required | Meaning |
| --- | --- | --- |
| `from`, `to` | yes | Days, `yyyy-MM-dd`, inclusive; at most 93 days |
| `tz` | no | Time zone the days are counted in, for example `Asia/Tashkent`; default UTC |
| `userIds` | no | Whose time (repeat the parameter for several). Default: only yours |

```bash
curl -G https://acme.sofiaspace.uz/api/v1/orgs/6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20/timesheet \
  -H "Authorization: Bearer $SOFIA_TOKEN" \
  --data-urlencode "from=2026-11-09" \
  --data-urlencode "to=2026-11-15" \
  --data-urlencode "tz=Asia/Tashkent" \
  --data-urlencode "userIds=8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62"
```

```json
{
  "people": ["8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62"],
  "hiddenPeople": [],
  "cells": [
    { "userId": "8e4d2b19-6c7a-4f3e-b1d0-3a5c9e8f7d62", "taskId": "7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20", "taskKey": "SALES-42", "taskTitle": "Onboard new customer (deal #1042)", "projectId": "9d2e7a10-4b6c-4e8f-a1d3-5c7e9b2f4a68", "day": "2026-11-13", "minutes": 150 }
  ]
}
```

- `cells` has one entry per person, task and day with time logged; days with nothing logged are left out.
- Your own time comes from every project you can open. **Other people's** time comes only from projects where you may see per-person numbers: Org Admins, Project Admins and roles with **See people analytics**. If you may see per-person numbers in none of your projects, the other people you asked for are listed in `hiddenPeople` instead.

Errors: `400 RANGE_TOO_LONG` for more than 93 days or `from` after `to`; `400 TIME_ZONE_INVALID` for an unknown `tz`.

## What you can't do with the API

- You can't delete a worklog with a token (`403 SIGNED_IN_APP_ONLY`); edit it instead, or delete it in the app.
- You can't run a timer for someone else: the timer is always the token owner's own.
- You can't switch time tracking on for a project, or change its rules, through the API.
- Need hours per person over a period, with tasks done and on-time rate? Use the [KPI export](https://docs.sofiaspace.uz/api/integrations.md#export-kpis-per-person).

## Related

- [Time tracking](https://docs.sofiaspace.uz/tasks/time-tracking.md) — in the app
- [Tasks](https://docs.sofiaspace.uz/api/tasks.md)
- [Integrations API](https://docs.sofiaspace.uz/api/integrations.md) — the KPI export
