# Alerts API

These instructions apply to the current Admin Console.

{% hint style="info" %}
Alerts are in early access and may not be available in your account. [Contact Contextual support](mailto:help@contextual.io) to request that Alerts be enabled for your tenant.
{% endhint %}

Use the Alerts API to manage configuration, validate drafts, inspect alert instances, and manage the tenant's background metrics connection.

## Base URL and Authentication

Use the Alerts API base URL supplied by your administrator. The base URL includes `/api/v1`, as in `https://alerts.example.com/api/v1`. Replace the example hostname with your assigned host.

Direct requests require a bearer token accepted by that service's configured audience and an organization ID in `x-org-id`. The service verifies organization membership and operation permissions.

In shell examples, set `ALERTS_BASE_URL`, `ALERTS_TOKEN`, and `ALERTS_ORG_ID` securely for direct API requests. Use no trailing slash in the base URL. This read-only request lists templates:

```sh
curl --fail-with-body --silent --show-error \
  "$ALERTS_BASE_URL/templates" \
  -H "Authorization: Bearer $ALERTS_TOKEN" \
  -H "x-org-id: $ALERTS_ORG_ID"
```

Do not put tokens or destination URLs in committed files or shared logs. URL-encode IDs used in route segments and preserve their case.

## Swagger UI and OpenAPI

The Alerts service hosts Swagger UI at `/api-docs/` and its OpenAPI 3.1 document at `/api-docs/openapi.json`. For a service hosted at `https://alerts.example.com`, the URLs are `https://alerts.example.com/api-docs/` and `https://alerts.example.com/api-docs/openapi.json`. Replace the example hostname with your assigned host. These paths are outside `/api/v1`; do not append them to the API base. Ask your administrator for the documentation URL if these paths are unavailable.

The documentation endpoints are public. API operations still require authentication, organization membership, permissions, and enabled capabilities. To use **Try it out**, select **Authorize**, enter an accepted access token without the `Bearer ` prefix, and supply `x-org-id` for the operation. Write operations change tenant configuration, and destination reveal operations return real credentials.

Use the served contract for the deployed version's operation schemas, parameters, permissions, and responses. This guide explains workflows and interpretation; it complements the machine-readable contract. The contract covers metrics enrollment as well as the other Alerts operations.

## References

* [Configuration](https://docs.contextual.io/tenants/tenant-apis/alerts-api/configuration.md): templates, rules, destinations, subscriptions, silences, and declarative apply.
* [Rule Validation and Preview Endpoints](https://docs.contextual.io/tenants/tenant-apis/alerts-api/validation-and-preview.md): authoring checks and bounded historical observations.
* [Alert Operations](https://docs.contextual.io/tenants/tenant-apis/alerts-api/alert-operations.md): active alerts, history, delivery details, and dismissal.
* [Metrics Enrollment](https://docs.contextual.io/tenants/tenant-apis/alerts-api/metrics-enrollment.md): status, setup, reconnect, notifications, and cleanup.

## Errors and Availability

Errors use `application/json` with `code` (a string or number), `message`, and optional `errors`. For example, validation failures use `code: validation_error`. Preserve the HTTP status, response body, and relevant headers such as `Retry-After` when diagnosing a request; do not expect RFC 7807 `type` or `detail` fields.

| Status | Typical cause |
| --- | --- |
| `400` | Invalid input or unsupported authoring shape |
| `401` | Missing or invalid authentication |
| `403` | Missing membership, permissions, or access |
| `404` | Resource not found in the accessible scope |
| `409` | Operation conflicts with state, including enrollment required or ineligible dismissal |
| `412` | Stale hash on a guarded write |
| `429` | Request admission limit; inspect `Retry-After` |
| `501` | Preview capability unavailable for the requested source/history |
| `502` / `503` | Upstream evidence, dependency, or temporary availability failure |

Where available, `GET /capabilities` reports access, capability state (`enabled`, `paused`, or `unavailable`), and permitted actions such as inspect, author, and cleanup. Do not infer that every operation is available from a visible navigation item. At the API, a known pause can still permit inspection and narrowly defined disable/delete cleanup. The Admin Console hides Alerts navigation and blocks the Alerts page when the platform capability is not enabled; it is not a paused-tenant cleanup interface.
