# Sites API

> List the sites you staff. GET /api/v1/facilities, GET /api/v1/facilities/{id}, GET /api/v1/facilities/{id}/contacts, POST /api/v1/facilities/{id}/contacts.

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/facilities`](#get-api-v1-facilities) | `roster:read` |
| [`GET /api/v1/facilities/{id}`](#get-api-v1-facilities-id) | `roster:read` |
| [`GET /api/v1/facilities/{id}/contacts`](#get-api-v1-facilities-id-contacts) | `relationships:read` |
| [`POST /api/v1/facilities/{id}/contacts`](#post-api-v1-facilities-id-contacts) | `relationships:write` |

## GET /api/v1/facilities

Your sites.

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

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `includeArchived` | true to include retired sites. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `name`, `code`, `state`, `timezone`, `externalId`, `postalCode`, `address`, `archived`

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

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

One site.

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

**Path**

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

**Fields in each record:** `id`, `name`, `code`, `state`, `timezone`, `externalId`, `postalCode`, `address`, `archived`

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

## GET /api/v1/facilities/{id}/contacts

The people at a site, from its Relationship record.

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

**Path**

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

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `recordType`, `recordId`, `name`, `title`, `email`, `phone`, `getsFacilityEmails`, `getsDailyRoster`, `primary`, `createdAt`

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

## POST /api/v1/facilities/{id}/contacts

Add a contact to a site's record. Up to 25 a site.

- **Permission:** `relationships: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 |
| --- | --- |
| `name` | Required. |
| `title` | — |
| `email` | Required when either box below is true. |
| `phone` | — |
| `getsFacilityEmails` | true: forms sent to the facility, including automatic shift feedback requests, go to them. |
| `getsDailyRoster` | true: they get the daily roster email. |
| `primary` | true: the main contact. |

**Fields in each record:** `id`, `recordType`, `recordId`, `name`, `title`, `email`, `phone`, `getsFacilityEmails`, `getsDailyRoster`, `primary`, `createdAt`

```bash
curl -X POST "https://app.staffedly.com/api/v1/facilities/<id>/contacts" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"name":"Jordan Avery","email":"jordan.avery@example.com"}'
```

