# Idempotency

> Retry creating requests safely with the Idempotency-Key header.

A network error after a `POST` leaves you not knowing whether the resource was created. Send an `Idempotency-Key` with creating requests, and retry with the same key:

```sh title="Create a check, safe to retry"
curl -fsS https://app.monitorly.cloud/api/v1/projects/$PROJECT/checks \
  -H "Authorization: Bearer $MONITORLY_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 4f1d2c8e-deploy-1842" \
  --data @check.json
```

- The key is 1 to 255 characters of your choice; a UUID per intended action works well.
- A repeat with the same key and the same request returns the stored response, status and body, and creates nothing.
- The same key with another method, path or body answers `422 request.idempotency_key_reused`.
- Keys are kept for 24 hours.
- An empty or too long key answers `400 request.idempotency_key_invalid`.

## Which operations take it

| Operation                                                                          | Request                                                     |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| [Create a workspace](https://docs.monitorly.cloud/api/reference/operations/create-workspace.md)                  | `POST /api/v1/workspaces`                                   |
| [Create a project](https://docs.monitorly.cloud/api/reference/operations/create-project.md)                      | `POST /api/v1/workspaces/{workspaceId}/projects`            |
| [Create a check](https://docs.monitorly.cloud/api/reference/operations/create-check.md)                          | `POST /api/v1/projects/{projectId}/checks`                  |
| [Create a maintenance window](https://docs.monitorly.cloud/api/reference/operations/create-maintenance.md)       | `POST /api/v1/projects/{projectId}/maintenance`             |
| [Create a status page](https://docs.monitorly.cloud/api/reference/operations/create-status-page.md)              | `POST /api/v1/projects/{projectId}/status-pages`            |
| [Post an incident](https://docs.monitorly.cloud/api/reference/operations/create-status-page-incident.md)         | `POST /api/v1/status-pages/{pageId}/incidents`              |
| [Add an update to a post](https://docs.monitorly.cloud/api/reference/operations/add-status-page-update.md)       | `POST /api/v1/page-incidents/{incidentId}/updates`          |
| [Create an escalation policy](https://docs.monitorly.cloud/api/reference/operations/create-escalation-policy.md) | `POST /api/v1/workspaces/{workspaceId}/escalation-policies` |
| [Invite a member](https://docs.monitorly.cloud/api/reference/operations/create-invite.md)                        | `POST /api/v1/workspaces/{workspaceId}/invites`             |
| [Create an API token](https://docs.monitorly.cloud/api/reference/operations/create-api-token.md)                 | `POST /api/v1/workspaces/{workspaceId}/api-tokens`          |

Other creating requests ignore the header. Alert channels refuse a second channel to the same address with `409 alert_channel.duplicate`; a config apply is safe to retry as it is: applying the same plan again answers the result of its first apply; join tokens, link codes, test runs and exports are new on every call.
