> For the complete documentation index, see [llms.txt](https://teamleader-sdk.mcore-services.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://teamleader-sdk.mcore-services.dev/api-reference/time-tracking/timers.md).

# Timers

Manage time tracking timers in Teamleader Focus.

```php
Teamleader::timers()
```

|                          |                                                             |
| ------------------------ | ----------------------------------------------------------- |
| Class                    | `McoreServices\TeamleaderSDK\Resources\TimeTracking\Timers` |
| Create / update / delete | ✓ / ✓ / —                                                   |
| Pagination               | No                                                          |

## Endpoints

* `timers.current`
* `timers.start`
* `timers.stop`
* `timers.update`

## Filters

`list()` takes no filters.

## Accepted values

Public constants on the class. Body fields and enum values outside these lists throw before the request is sent.

| Constant        | Values                                                                |
| --------------- | --------------------------------------------------------------------- |
| `SUBJECT_TYPES` | `company`, `contact`, `event`, `todo`, `milestone`, `ticket`          |
| `WRITE_FIELDS`  | `work_type_id`, `started_at`, `description`, `subject`, `invoiceable` |

## Methods

### `start()`

```php
start(array $data): array
```

Start a new timer

* `$data` — Timer data

**Throws** `InvalidArgumentException`

### `startForSubject()`

```php
startForSubject(string $subjectType, string $subjectId, string $workTypeId, array $options = []): array
```

Start a timer for a specific subject (convenience method)

* `$subjectType` — Type of subject (company, contact, event, todo, milestone, ticket)
* `$subjectId` — UUID of the subject
* `$workTypeId` — UUID of the work type
* `$options` — Additional options (description, invoiceable, started\_at)

### `current()`

```php
current(): array
```

Get the current running timer

### `stop()`

```php
stop(): array
```

Stop the current timer This will add a new time tracking entry in the background

### `updateCurrent()`

```php
updateCurrent(array $data): array
```

Update the current timer Only possible if there is a timer running

### `update()`

```php
update(array $data): array
```

Alias for updateCurrent()

The usage examples called `timers()->update()` until v2.2.11, when no such method existed; it is kept so code written from them works.

* `$data` — Fields to change on the running timer

### `isRunning()`

```php
isRunning(): bool
```

Check if there is a timer currently running

### `getAvailableSubjectTypes()`

```php
getAvailableSubjectTypes(): array
```

Get available subject types

## Examples

Start a new timer for a company:

```php
$timer = Teamleader::timers()->start([
    'work_type_id' => 'work-type-uuid',
    'subject' => [
        'type' => 'company',
        'id' => 'company-uuid'
    ],
    'description' => 'Working on project',
    'invoiceable' => true
]);
```

Start a timer for a ticket:

```php
$timer = Teamleader::timers()->startForSubject(
    'ticket',
    'ticket-uuid',
    'work-type-uuid',
    ['description' => 'Fixing bug', 'invoiceable' => true]
);
```

Get the currently running timer:

```php
$currentTimer = Teamleader::timers()->current();
```

Update the current timer description:

```php
$result = Teamleader::timers()->updateCurrent(['description' => 'Updated description']);
```

Stop the current timer:

```php
$result = Teamleader::timers()->stop();
```
