# Credentials API

> Read licenses and certifications, and add or update them. GET /api/v1/credentials, POST /api/v1/credentials, PATCH /api/v1/credentials/{id}.

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/credentials`](#get-api-v1-credentials) | `credentials:read` |
| [`POST /api/v1/credentials`](#post-api-v1-credentials) | `credentials:write` |
| [`PATCH /api/v1/credentials/{id}`](#patch-api-v1-credentials-id) | `credentials:write` |

## GET /api/v1/credentials

Licenses and certifications by person. License numbers are never returned.

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

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `providerId` | Only this person. |
| `status` | current, expiring_soon, expired or missing. |
| `type` | A credential type, such as license. |
| `expiresBefore` | Expiring before this date (YYYY-MM-DD). |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `providerId`, `type`, `state`, `facilityId`, `status`, `expiresAt`

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

## POST /api/v1/credentials

Add a license or certification to a person.

- **Permission:** `credentials: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. |
| `type` | Required. One of your credential types, such as license. |
| `state` | Two letters. |
| `facilityId` | Required for facility_privilege. |
| `expiresAt` | YYYY-MM-DD. |
| `identifier` | The license number. Stored encrypted, never returned. |

**Fields in each record:** `id`, `providerId`, `type`, `state`, `facilityId`, `status`, `expiresAt`

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

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

Update a credential on file, such as a renewal's new expiry. Its status follows the date.

- **Permission:** `credentials: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 |
| --- | --- |
| `expiresAt` | YYYY-MM-DD, or null for no expiry. |
| `state` | Two letters. |
| `identifier` | The number. Stored encrypted, never returned. |

**Fields in each record:** `id`, `providerId`, `type`, `state`, `facilityId`, `status`, `expiresAt`

```bash
curl -X PATCH "https://app.staffedly.com/api/v1/credentials/<id>" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"expiresAt":"2028-06-30","state":"NY"}'
```

