# Add a webhook endpoint

> Subscribe a public https URL to events on your deals, campaigns and posts: the REST Hooks subscribe call automation tools make when a trigger is turned on. Returns the endpoint and its signing secret (`whsec_…`), shown this once. Same rules as Settings → Webhooks: no private or local addresses, no yapfactory.com URLs.

```http
POST https://yapfactory.com/api/v1/webhooks
```

|   |   |
| --- | --- |
| Who can use it | Everyone: brands and creators |
| Tier | `write`: Changes your own things only. Nobody else is told. |
| Scope | `webhooks:write`, or `write` |
| Idempotency-Key | Optional, and recommended |
| Rate limit | Writes: 20 a minute |
| MCP tool | None. This one is REST only. |

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `url` | body | `string` | yes | The public https URL events are POSTed to. 1 to 2000 characters. |
| `events` | body | `("*" \| "deal.updated" \| "deal.invited" \| "invite.accepted" \| "invite.declined" \| "invite.expired" \| "deal.started" \| "draft.submitted" \| "revision.requested" \| "draft.approved" \| "deal.completed" \| "deal.cancelled" \| "ask.received" \| "message.received" \| "campaign.published" \| "post.published" \| "post.failed")[]` | yes | Event types to send, or ["*"] for all of them. 1 to 16 items. |
| `description` | body | `string` | no | A label shown in Settings, such as "Zapier: new draft". Up to 120 characters. |

## Example request

```bash
curl -X POST "https://yapfactory.com/api/v1/webhooks" \
  -H "Authorization: Bearer $YAP_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://hooks.zapier.com/hooks/standard/1234567/abcdef/",
    "events": [
      "draft.submitted"
    ],
    "description": "Zapier: draft ready to review"
  }'
```

## Response

`201` with the result in `data`.

```json
{
  "data": {
    "id": "0d61f837-1c3b-4e4a-8a5f-7b2e9c6d1f00",
    "url": "https://hooks.zapier.com/hooks/standard/1234567/abcdef/",
    "description": "Zapier: draft ready to review",
    "events": [
      "draft.submitted"
    ],
    "enabled": true,
    "secret": "whsec_8fK2mQ9xLp3VtR7nYc1B4dE6gH0jK2mN",
    "manage": "https://yapfactory.com/brand/settings#webhooks"
  }
}
```

An example: fields that don't apply are `null`, and new fields can be added at any time, so ignore ones you don't know. Every response carries `Request-Id` and the `RateLimit-*` headers.

## Errors

| Code | Status | When |
| --- | --- | --- |
| `invalid_request` | 400 | A field failed validation (see `meta.issues`), or an unknown query parameter. |
| `unauthorized` | 401 | No token, or it's wrong, expired, revoked or from the other environment. |
| `insufficient_scope` | 403 | The token doesn't have `webhooks:write` (or `write`). |
| `forbidden` | 403 | Not allowed for this account, for example while it's paused. |
| `conflict` | 409 | Its current state doesn't allow this. `message` says why, in words you can show. |
| `idempotency_conflict` | 409 | The same `Idempotency-Key` came with a different body. |
| `rate_limited` | 429 | Over the limit. Wait for `Retry-After` seconds. |
| `internal` | 500 | Our fault. Retry later, and send us the `requestId` if it keeps happening. |

Every error has the same shape. See [Errors](https://yapfactory.com/developers/errors.md) for what to do about each one.

---

HTML version: https://yapfactory.com/developers/api/create_webhook
