# domains.setEventWebhook

Create or replace the domain's event webhook.

One URL per domain, all events, no filters. Mailboxes on the domain start feeding it within seconds (a background walk arms them) — take a baseline first and treat the first batches as deltas. Any PUT re-enables, and re-runs the arm walk: it is the recovery if a walk ever died mid-domain (visible as a dead_lettered `arm:<domain>` row in the delivery log). What your endpoint receives (payload, `X-OpenEmail-Signature` scheme, retry policy) is specified as `event-batch` in this document's top-level `webhooks` section.

```ts
openemail.domains.setEventWebhook(
  domain: string,
  body: DomainsSetEventWebhookBody,
  options?: CallOptions,
): ApiPromise<EventWebhook>
```

It calls `PUT /domains/{domain}/event-webhook`: [Create or replace the domain's event webhook](/docs/api/domains/put_DomainEventWebhookSet) in the API reference.

## Example

```ts
const eventWebhook = await openemail.domains.setEventWebhook(domain, {
  secret: 'whsec_5e8a1c9f2b7d4e6a8c1f3b5d7e9a2c4f',
  url: 'https://hooks.acme.example/openemail',
})
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `domain` | `string` | Domain name. The path's `{domain}`. |
| `body` | [`DomainsSetEventWebhookBody`](#domainsseteventwebhookbody) | The request's body. |

## Options

It takes no options of its own. Every call also takes `signal`, `timeout`, `retry` and `headers`, which say how that one call is sent ([call options](/docs/sdks/typescript/calling-methods#call-options)).

## Answer

Awaited, it is the API's JSON, [`EventWebhook`](/docs/sdks/typescript/types/event-webhook). It is an [`ApiPromise`](/docs/sdks/typescript/responses): `.withResponse()` gives the same with the `Response` it came in, for its headers.

## Errors

| Status | What it means |
| --- | --- |
| `400` | validation_failed — URL refused |
| `401` | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge |
| `404` | Domain not found or not accessible to this principal |
| `409` | account_required: the domain has no owning account, and a hook row must reference one (the legacy directory; once the partitioned directory answers, a platform domain's hook is accepted for the system caller) |
| `413` | too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing |
| `503` | temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description) |

A failed call rejects with a [`RequestError`](/docs/sdks/typescript/errors): its `status`, and its `code`, the API's `error`. Decide on the code: one status covers several.

## Types

### DomainsSetEventWebhookBody

```ts
/** The body of `domains.setEventWebhook`. */
type DomainsSetEventWebhookBody = {
  /** HMAC signing secret — write-only. Omit to keep, string to set, null to clear */
  secret?: string | null
  /** HTTPS endpoint on a public host */
  url: string
}
```

It names these types of the API, each on a page of its own: [`EventWebhook`](/docs/sdks/typescript/types/event-webhook).
