# Webhook Endpoints

> The endpoints iMario sends events to, test events, signing secrets and the delivery log. Owners and admins.

Source: https://imario.ai/docs/api/reference/webhooks

Base URL `https://api.imario.ai/v1`. Each call needs a key that holds the scope shown and acts with at least the role shown ([Authentication](https://imario.ai/docs/api/authentication)). Errors are described in [API errors](https://imario.ai/docs/api/errors).

## List webhook endpoints

`GET /v1/webhook-endpoints`

**Scope** `webhooks:read` · **Role** owner or admin

The endpoints of the key's mode (live or test), newest first. A `webhook_endpoint`: `id`, `livemode` (a test key's endpoints are test endpoints and receive sandbox events only), `created_at`, `url`, `description`, `events` (event types, or `["*"]` for all), `enabled`, `disabled_reason` (`delivery_failures` when iMario turned it off after 3 days of failed deliveries, `disabled_by_user`, or null).

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `limit` | query | `integer` | No | How many objects to return (1-100). Default `20`. |
| `cursor` | query | `string` | No | The `next_cursor` of the previous page. Up to 200 characters. |

**Example**

```bash
curl https://api.imario.ai/v1/webhook-endpoints \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

**Response**

Returns a list: `{"object": "list", "data": [...], "has_more": false, "next_cursor": null}`. See [Pagination](https://imario.ai/docs/api/pagination).

## Create a webhook endpoint

`POST /v1/webhook-endpoints`

**Scope** `webhooks:write` · **Role** owner or admin

The response carries `secret` (`whsec_...`), shown this once: keep it to verify `webhook-signature` (Standard Webhooks). The URL must be https and resolve to public addresses only; it is checked again at every delivery. A `webhook_endpoint`: `id`, `livemode` (a test key's endpoints are test endpoints and receive sandbox events only), `created_at`, `url`, `description`, `events` (event types, or `["*"]` for all), `enabled`, `disabled_reason` (`delivery_failures` when iMario turned it off after 3 days of failed deliveries, `disabled_by_user`, or null).

**Request body**

| Field | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | Yes | A public https URL. Redirects are not followed. Up to 2,048 characters. |
| `events` | `string[]` | Yes | Event types to receive, or ["*"] for every type. Up to 20 items. |
| `description` | `string` | No | Up to 200 characters. |

**Example**

```bash
curl https://api.imario.ai/v1/webhook-endpoints \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/imario/webhooks",
    "events": ["study.completed", "study.failed", "report.completed"],
    "description": "Production receiver"
  }'
```

## Retrieve a webhook endpoint

`GET /v1/webhook-endpoints/{endpoint_id}`

**Scope** `webhooks:read` · **Role** owner or admin

A `webhook_endpoint`: `id`, `livemode` (a test key's endpoints are test endpoints and receive sandbox events only), `created_at`, `url`, `description`, `events` (event types, or `["*"]` for all), `enabled`, `disabled_reason` (`delivery_failures` when iMario turned it off after 3 days of failed deliveries, `disabled_by_user`, or null).

**Example**

```bash
curl https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

## Update a webhook endpoint

`PATCH /v1/webhook-endpoints/{endpoint_id}`

**Scope** `webhooks:write` · **Role** owner or admin

Send only the fields to change. A `webhook_endpoint`: `id`, `livemode` (a test key's endpoints are test endpoints and receive sandbox events only), `created_at`, `url`, `description`, `events` (event types, or `["*"]` for all), `enabled`, `disabled_reason` (`delivery_failures` when iMario turned it off after 3 days of failed deliveries, `disabled_by_user`, or null).

**Request body**

| Field | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | No | Up to 2,048 characters. |
| `events` | `string[]` | No | Up to 20 items. |
| `description` | `string` | No | Up to 200 characters. |
| `enabled` | `boolean` | No | false stops deliveries (and drops the pending ones); true turns the endpoint on again. |

**Example**

```bash
curl -X PATCH https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'
```

## Delete a webhook endpoint

`DELETE /v1/webhook-endpoints/{endpoint_id}`

**Scope** `webhooks:write` · **Role** owner or admin

Deliveries waiting for it are dropped. Returns `{object, id, deleted: true}`.

**Example**

```bash
curl -X DELETE https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

## Send a test event

`POST /v1/webhook-endpoints/{endpoint_id}/test`

**Scope** `webhooks:write` · **Role** owner or admin

Queues a `ping` event to this endpoint alone (its `data.object` is the endpoint) and returns the `webhook_delivery`: `id`, `endpoint_id`, `event_id`, `event_type`, `status` (pending, delivered, failed), `attempts`, `last_status_code`, `last_error`, `created_at`, `delivered_at`, `next_attempt_at`.

**Example**

```bash
curl -X POST https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/test \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

## Rotate the signing secret

`POST /v1/webhook-endpoints/{endpoint_id}/rotate-secret`

**Scope** `webhooks:write` · **Role** owner or admin

A new `secret`, shown this once. For 24 hours deliveries carry two signatures (the new secret's and the old one's), so a receiver can switch without missing an event. A `webhook_endpoint`: `id`, `livemode` (a test key's endpoints are test endpoints and receive sandbox events only), `created_at`, `url`, `description`, `events` (event types, or `["*"]` for all), `enabled`, `disabled_reason` (`delivery_failures` when iMario turned it off after 3 days of failed deliveries, `disabled_by_user`, or null).

**Example**

```bash
curl -X POST https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/rotate-secret \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

## List an endpoint's deliveries

`GET /v1/webhook-endpoints/{endpoint_id}/deliveries`

**Scope** `webhooks:read` · **Role** owner or admin

Newest first, kept 30 days. Each `webhook_delivery`: `id`, `endpoint_id`, `event_id` (the `webhook-id` header), `event_type`, `status` (pending, delivered, failed), `attempts`, `last_status_code`, `last_error`, `created_at`, `delivered_at`, `next_attempt_at`. A failed attempt is tried again after 1 min, 5 min, 30 min, 2 h, 6 h and 12 h.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `limit` | query | `integer` | No | How many objects to return (1-100). Default `20`. |
| `cursor` | query | `string` | No | The `next_cursor` of the previous page. Up to 200 characters. |

**Example**

```bash
curl https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/deliveries \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

**Response**

Returns a list: `{"object": "list", "data": [...], "has_more": false, "next_cursor": null}`. See [Pagination](https://imario.ai/docs/api/pagination).
