# Time off API

> Read, add, change and withdraw time off. GET /api/v1/leave, POST /api/v1/leave, POST /api/v1/leave/{id}/approve, POST /api/v1/leave/{id}/cancel and more.

5 operations. Each needs an API key with the permission shown; see [API keys and permissions](https://staffedly.com/docs/developers/api-keys).

| Operation | Permission |
| --- | --- |
| [`GET /api/v1/leave`](#get-api-v1-leave) | `leave:read` |
| [`POST /api/v1/leave`](#post-api-v1-leave) | `leave:write` |
| [`POST /api/v1/leave/{id}/approve`](#post-api-v1-leave-id-approve) | `leave:write` |
| [`POST /api/v1/leave/{id}/cancel`](#post-api-v1-leave-id-cancel) | `leave:write` |
| [`PATCH /api/v1/leave/{id}`](#patch-api-v1-leave-id) | `leave:write` |

## GET /api/v1/leave

Time off, requested and approved. Whole days: start and end are the first and last day, given as midday UTC.

- **Permission:** `leave:read`
- **Returns:** a page of records: `{ data, hasMore, nextCursor }`, status 200

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `status` | requested, approved, active, returned or cancelled. |
| `providerId` | Only this person. |
| `from` | Leave that ends after this date. |
| `to` | Leave that starts before this date. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `providerId`, `type`, `status`, `start`, `end`, `requestedAt`, `externalId`

```bash
curl "https://app.staffedly.com/api/v1/leave?limit=50" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## POST /api/v1/leave

Add time off, as a request or already approved.

- **Permission:** `leave:write`
- **Returns:** one record: `{ data }`, status 201
- **Safe retry:** send an `Idempotency-Key` header (8 to 128 characters); the same key with the same request returns the first answer again

**Body fields** (JSON; a field the API does not know is refused)

| Field | Description |
| --- | --- |
| `providerId` | Required. |
| `start` | Required. First day, YYYY-MM-DD. |
| `end` | Last day, YYYY-MM-DD. Default: the same day. |
| `type` | vacation, short_term_disability, medical, personal or other (default). |
| `status` | requested (default) or approved. |

**Fields in each record:** `id`, `providerId`, `type`, `status`, `start`, `end`, `requestedAt`, `externalId`

```bash
curl -X POST "https://app.staffedly.com/api/v1/leave" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"providerId":"<providerId>","start":"2027-01-12"}'
```

## POST /api/v1/leave/{id}/approve

Approve requested time off. The person is told; shifts they still hold on those days are raised for your schedulers.

- **Permission:** `leave:write`
- **Returns:** one record: `{ data }`, status 201
- **Safe retry:** send an `Idempotency-Key` header (8 to 128 characters); the same key with the same request returns the first answer again

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Body fields** (JSON; a field the API does not know is refused)

| Field | Description |
| --- | --- |
| `note` | Sent to the person. |

**Fields in each record:** `id`, `providerId`, `type`, `status`, `start`, `end`, `requestedAt`, `externalId`

```bash
curl -X POST "https://app.staffedly.com/api/v1/leave/<id>/approve" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"note":"Family trip"}'
```

## POST /api/v1/leave/{id}/cancel

Withdraw time off that is requested, approved or under way. The person is told.

- **Permission:** `leave:write`
- **Returns:** one record: `{ data }`, status 201
- **Safe retry:** send an `Idempotency-Key` header (8 to 128 characters); the same key with the same request returns the first answer again

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Body fields** (JSON; a field the API does not know is refused)

| Field | Description |
| --- | --- |
| `reason` | Sent to the person. |

**Fields in each record:** `id`, `providerId`, `type`, `status`, `start`, `end`, `requestedAt`, `externalId`

```bash
curl -X POST "https://app.staffedly.com/api/v1/leave/<id>/cancel" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Extra room opened"}'
```

## PATCH /api/v1/leave/{id}

Change the dates or kind of time off that is requested or approved. The person is told.

- **Permission:** `leave:write`
- **Returns:** one record: `{ data }`, status 200
- **Safe retry:** send an `Idempotency-Key` header (8 to 128 characters); the same key with the same request returns the first answer again

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Body fields** (JSON; a field the API does not know is refused)

| Field | Description |
| --- | --- |
| `start` | First day, YYYY-MM-DD. |
| `end` | Last day, YYYY-MM-DD. |
| `type` | vacation, short_term_disability, medical, personal or other. |

**Fields in each record:** `id`, `providerId`, `type`, `status`, `start`, `end`, `requestedAt`, `externalId`

```bash
curl -X PATCH "https://app.staffedly.com/api/v1/leave/<id>" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"start":"2027-01-12","end":"2027-01-14"}'
```

