## Start task timer

`POST /v1/tasks/:taskId/start-timer`

Starts the time-tracking timer for a task on behalf of the key's user. A task in the Pending status moves to In Progress.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `taskId` (path) | number | yes | Task ID. List: [`GET /v1/tasks`](/docs/entities/tasks/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `params` | object | no | Additional action parameters. Passed to Bitrix24 unchanged |
| `params.STOP_PREVIOUS` | string | no | `Y` — before starting, stop the timer the key's user started on another task. The value `N` and an absent field behave the same: while a timer runs on another task, the call is rejected with `422` |

The request body can be empty or `{}`. Any field other than `params` is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/289/start-timer' \
  -H 'X-Api-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"params":{"STOP_PREVIOUS":"Y"}}'
```

### curl — OAuth application

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/289/start-timer' \
  -H 'X-Api-Key: YOUR_APP_KEY' \
  -H 'Authorization: Bearer USER_SESSION_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"params":{"STOP_PREVIOUS":"Y"}}'
```

### JavaScript — personal key

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/289/start-timer', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"params":{"STOP_PREVIOUS":"Y"}}),
})
const result = await response.json()
console.log(result.data)
```

### JavaScript — OAuth application

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/289/start-timer', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"params":{"STOP_PREVIOUS":"Y"}}),
})
const result = await response.json()
console.log(result.data)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data` | object \| null | `null` if time tracking is off for the task. The timer does not start in that case |
| `data.task` | object | The full task object when time tracking is on. Values arrive in raw form: numbers as strings (`"id": "289"`), flags as `Y` or `N` (`"allowTimeTracking": "Y"`). [`GET /v1/tasks/:id`](/docs/entities/tasks/get) returns the same fields as numbers and `true`/`false` |
| `data.task.id` | string | Task ID |
| `data.task.allowTimeTracking` | string | Time tracking for the task: `Y` — on |
| `data.task.timeElapsed` | string | Time already tracked on the task, in seconds |
| `data.task.action` | object | Which actions the key's user can take: the key is the action name (`start`, `pause`, `complete`, `defer`, `renew` and others), the value is `true` or `false` |

## Response example

Time tracking is on. Only the main fields of the task object are shown:

```json
{
  "success": true,
  "data": {
    "task": {
      "id": "289",
      "title": "Prepare the quarterly report",
      "status": "3",
      "createdBy": "1",
      "responsibleId": "1",
      "allowTimeTracking": "Y",
      "timeElapsed": "6",
      "action": {
        "start": false,
        "pause": true,
        "complete": true,
        "defer": false,
        "renew": false
      }
    }
  }
}
```

Time tracking is off for the task:

```json
{
  "success": true,
  "data": null
}
```

## Error response example

422 — the key's user already has a timer running on another task, and `STOP_PREVIOUS` is not passed:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Another task (##287#) is now currently active. Please stop it before proceeding.",
    "b24Code": "0"
  }
}
```

The `error.message` text comes from Bitrix24, so its wording and language depend on the Bitrix24 account language. Branch on `error.code`, not on the message text.

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `taskId` is not a positive integer: `taskId must be a positive integer` |
| 400 | `INVALID_PARAMS` | The request body is not a JSON object: `body must be an object` |
| 400 | `INVALID_PARAMS` | The body contains fields other than `params`: `body contains unsupported fields` |
| 400 | `INVALID_PARAMS` | `params` is not an object: `params must be an object` |
| 401 | `MISSING_API_KEY` | `X-Api-Key` is missing |
| 401 | `INVALID_API_KEY` | The key is not found |
| 401 | `TOKEN_MISSING` | The key has no valid Bitrix24 token |
| 403 | `SCOPE_DENIED` | The key lacks the `task` or `tasks` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |
| 403 | `BITRIX_ACCESS_DENIED` | The key's user has no rights to the task |
| 422 | `BITRIX_ERROR` | The key's user has a timer running on another task, and `STOP_PREVIOUS` is not `Y`: `Another task (##<id>#) is now currently active…` |
| 422 | `BITRIX_ERROR` | No task exists with this `taskId`: `Task not found or not accessible` |

The full list of common API errors — [Errors](/docs/errors).

## Known specifics

- **Without time tracking the timer does not start, yet the response is successful.** If `allowTimeTracking` is off for the task, the call returns `200` with `data: null`. The task status does not change, and no entry appears in [time tracking](/docs/entities/tasks/time). Time tracking is turned on by the `allowTimeTracking` field when you [create](/docs/entities/tasks/create) or [update](/docs/entities/tasks/update) the task.
- **A user can have only one timer running at a time.** With `STOP_PREVIOUS: "Y"` the timer on the other task stops, and its time is recorded in that task's time tracking.
- **The task object in the response does not reflect the start.** Its `timerIsRunningForCurrentUser` field arrives as `N`, and for a task that was Pending, `status` is still `2` although the task has already moved to In Progress. Read the current state with [`GET /v1/tasks/:id`](/docs/entities/tasks/get).
- **The timer stops with a separate call.** [Pausing the timer](/docs/entities/tasks/pause-timer) records the time worked in the task's [time tracking](/docs/entities/tasks/time).

## See also

- [Pause task timer](/docs/entities/tasks/pause-timer)
- [Task time tracking](/docs/entities/tasks/time)
- [Start task](/docs/entities/tasks/start)
- [Get task](/docs/entities/tasks/get)
- [Tasks](/docs/entities/tasks)
