# Add a webhook endpoint

`POST https://api.anyshop.io/v1/webhook_endpoints`

The answer carries its signing secret once. Endpoints must be public https addresses.

- Part of the [API reference](https://docs.anyshop.io/reference.md), [Webhooks and events](https://docs.anyshop.io/reference.md#webhooks).
- Scope: `webhooks:write`.
- Idempotent with Idempotency-Key.
- Works while the store is suspended.

## Body (application/json)

- `url` (string, required): A public https address, on port 443 or 8443. anyshop never follows redirects or calls private networks. Up to 2,048 characters.
- `description` (string): For you, up to 200 characters. Up to 200 characters.
- `events` ("all" or array of enums, required): "all" (now and later), or a list of event types. Values: `all`, `order.paid`, `order.fulfilled`, `order.refunded`, `dispute.created`, `stock.low`, `license.activated`.
- `signing` (enum): How deliveries are signed: hmac (a shared secret, the default) or ed25519. Values: `hmac`, `ed25519`.

## Headers

- `Idempotency-Key` (string): Up to 255 characters. A retry with the same key and request gets the first answer, without running twice (24 hours).

## Returns

The **webhook_endpoint** object.

## Errors

| Status | error.type | When |
| --- | --- | --- |
| 400 | `invalid_request` | The request is not valid; `error.param` names the field |
| 401 | `authentication` | No API key, or it is not valid |
| 403 | `permission` | The key does not have the scope this needs, or the store is suspended (store_suspended) |
| 404 | `not_found` | Not found in the key's store and mode |
| 409 | `conflict` | Conflicts with the object's state (type conflict), or an Idempotency-Key reused for another request (type idempotency, code idempotency_key_reused) |
| 429 | `rate_limited` | Too many requests; see Retry-After |

## Example

curl:

```bash
curl -X POST https://api.anyshop.io/v1/webhook_endpoints \
  -H "Authorization: Bearer $ANYSHOP_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/anyshop",
    "events": [
      "order.paid"
    ]
  }'
```

Node:

```js
const response = await fetch("https://api.anyshop.io/v1/webhook_endpoints", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ANYSHOP_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "url": "https://example.com/anyshop",
    "events": [
      "order.paid"
    ]
  }),
});
const answer = await response.json();
```

Python:

```python
import os
import requests
import uuid

response = requests.post(
    "https://api.anyshop.io/v1/webhook_endpoints",
    headers={
        "Authorization": f"Bearer {os.environ['ANYSHOP_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
      "url": "https://example.com/anyshop",
      "events": [
        "order.paid"
      ]
    },
)
answer = response.json()
```

Answer (200):

```json
{
  "object": "webhook_endpoint",
  "id": "whe_01m3rs9d2f4k6m8p0r2t4v6x8z",
  "url": "https://example.com/anyshop",
  "description": "",
  "livemode": true,
  "events": [
    "order.paid"
  ],
  "signing": "hmac",
  "status": "enabled",
  "disabled_reason": null,
  "failing_since": "2026-10-02T14:21:07.000Z",
  "created_at": "2026-10-02T14:21:07.000Z",
  "secret": {
    "object": "webhook_secret",
    "algorithm": "hmac",
    "value": "whsec_Q3s9mV1dGx7PqL2nW8rT5kZ0bY4cH6jF9aE1uS3oKP4="
  }
}
```

Answer (400):

```json
{
  "error": {
    "type": "invalid_request",
    "code": "invalid_body",
    "message": "The request is not valid; `error.param` names the field",
    "param": null
  }
}
```

Answer (409):

```json
{
  "error": {
    "type": "conflict",
    "code": "conflict",
    "message": "Conflicts with the object's state (type conflict), or an Idempotency-Key reused for another request (type idempotency, code idempotency_key_reused)",
    "param": null
  }
}
```

The IDs and keys in these examples are made up. Every schema is in the OpenAPI document, https://api.anyshop.io/v1/openapi.json.
