# Schedule API

> Read the published schedule and change who is working. GET /api/v1/assignments, POST /api/v1/assignments, GET /api/v1/assignments/{id}, POST /api/v1/assignments/{id}/cancel.

4 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/assignments`](#get-api-v1-assignments) | `schedule:read` |
| [`POST /api/v1/assignments`](#post-api-v1-assignments) | `schedule:publish` |
| [`GET /api/v1/assignments/{id}`](#get-api-v1-assignments-id) | `schedule:read` |
| [`POST /api/v1/assignments/{id}/cancel`](#post-api-v1-assignments-id-cancel) | `schedule:publish` |

## GET /api/v1/assignments

Who is working where and when. Draft schedules are never included.

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

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `from` | Earliest start time: YYYY-MM-DD or an ISO-8601 time. |
| `to` | Latest start time (not included): YYYY-MM-DD or an ISO-8601 time. |
| `providerId` | Only this person. |
| `facilityId` | Only this site. |
| `category` | shift or call. |
| `status` | published, modified, worked, released or cancelled. Default: published, modified, worked. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `start`, `end`, `operationalDate`, `category`, `status`, `callRole`, `callKind`, `externalId`

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

## POST /api/v1/assignments

Put someone on the live schedule. Every scheduling check runs; a shift that breaks a rule is refused with the reason. The person is told, as when your team adds a shift.

- **Permission:** `schedule:publish`
- **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. |
| `facilityId` | Required. |
| `start` | Required. ISO-8601 time with a zone, in the future. |
| `end` | Required. At most 36 hours after start. |
| `reason` | Required. Sent to the person. |
| `category` | shift (default) or call. |
| `callKind` | For call: in_house (default), home or backup. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `start`, `end`, `operationalDate`, `category`, `status`, `callRole`, `callKind`, `externalId`

```bash
curl -X POST "https://app.staffedly.com/api/v1/assignments" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"providerId":"<providerId>","facilityId":"<facilityId>","start":"2027-01-12T07:00:00-05:00","end":"2027-01-12T15:00:00-05:00","reason":"Extra room opened"}'
```

## GET /api/v1/assignments/{id}

One assignment.

- **Permission:** `schedule:read`
- **Returns:** one record: `{ data }`, status 200

**Path**

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

**Fields in each record:** `id`, `providerId`, `facilityId`, `start`, `end`, `operationalDate`, `category`, `status`, `callRole`, `callKind`, `externalId`

```bash
curl "https://app.staffedly.com/api/v1/assignments/<id>" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

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

Cancel a shift on the live schedule. The person is told, as when your team cancels one.

- **Permission:** `schedule:publish`
- **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` | Required. Sent to the person. |
| `cancelReason` | other (default) or facility_cancelled, which applies your late-cancel rule. |

**Fields in each record:** `id`, `providerId`, `facilityId`, `start`, `end`, `operationalDate`, `category`, `status`, `callRole`, `callKind`, `externalId`

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

