# Open shifts API

> List shifts waiting to be filled and post new ones. GET /api/v1/open-shifts, POST /api/v1/open-shifts, POST /api/v1/open-shifts/{id}/cancel.

3 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/open-shifts`](#get-api-v1-open-shifts) | `schedule:read` |
| [`POST /api/v1/open-shifts`](#post-api-v1-open-shifts) | `schedule:write` |
| [`POST /api/v1/open-shifts/{id}/cancel`](#post-api-v1-open-shifts-id-cancel) | `schedule:write` |

## GET /api/v1/open-shifts

Shifts waiting to be filled.

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

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `status` | open, offered, reserved, filled, expired or cancelled. Default: open, offered, reserved. |
| `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. |
| `facilityId` | Only this site. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `facilityId`, `start`, `end`, `role`, `category`, `skill`, `severity`, `status`, `count`, `filledCount`, `source`, `createdAt`

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

## POST /api/v1/open-shifts

Post a shift to be filled. Offers go out according to your Automation settings.

- **Permission:** `schedule: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 |
| --- | --- |
| `facilityId` | Required. |
| `start` | Required. ISO-8601 time with a zone, in the future. |
| `end` | Required. At most 36 hours after start. |
| `role` | A role key or name. Default: your first role. |
| `count` | How many people are needed, 1 to 50. Default 1. |
| `severity` | normal (default), urgent or critical. |
| `skill` | Only offer to people with this skill. |

**Fields in each record:** `id`, `facilityId`, `start`, `end`, `role`, `category`, `skill`, `severity`, `status`, `count`, `filledCount`, `source`, `createdAt`

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

## POST /api/v1/open-shifts/{id}/cancel

Withdraw a shift that is still open or on offer. Offer links close.

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

**Fields in each record:** `id`, `facilityId`, `start`, `end`, `role`, `category`, `skill`, `severity`, `status`, `count`, `filledCount`, `source`, `createdAt`

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

