> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lettr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing Webhooks

> Manage webhook endpoints for delivery, open, click, bounce, and spam events with the client.webhooks resource in the Lettr Node.js SDK.

Webhooks deliver real-time notifications when emails are delivered, opened, clicked, bounced, or marked as spam. The `client.webhooks` resource manages your endpoints.

For the event payload format and signature verification, see [Webhooks](/learn/webhooks/introduction).

## List Webhooks

```typescript theme={null}
const { data, error } = await client.webhooks.list();

if (!error) {
  for (const webhook of data.webhooks) {
    console.log(webhook.id);
    console.log(webhook.name);
    console.log(webhook.url);
    console.log(webhook.enabled);
    console.log(webhook.auth_type);    // "none" | "basic" | "oauth2"
    console.log(webhook.last_status);  // last delivery status, or null

    // event_types is null when subscribed to all events
    if (webhook.event_types === null) {
      console.log("all events");
    } else {
      for (const event of webhook.event_types) {
        console.log(event); // "message.delivery", "engagement.click", ...
      }
    }
  }
}
```

<Card title="API Reference" icon="book" href="/api-reference/webhooks/list-webhooks">
  GET /webhooks
</Card>

## Create a Webhook

```typescript theme={null}
const { data, error } = await client.webhooks.create({
  name: "Production events",
  url: "https://example.com/webhooks/lettr",
  auth_type: "none",
  events_mode: "selected",
  events: ["message.delivery", "message.bounce", "engagement.click"],
});

if (!error) console.log(data.id);
```

<Note>
  Use `events_mode: "all"` to receive every event type (no `events` array needed), or `events_mode: "selected"` with an explicit `events` array. For authenticated endpoints set `auth_type` to `"basic"` or `"oauth2"` and supply the matching credentials (`auth_username`/`auth_password` or the `oauth_*` fields).
</Note>

<Card title="API Reference" icon="book" href="/api-reference/webhooks/create-webhook">
  POST /webhooks
</Card>

## Get a Webhook

```typescript theme={null}
const { data, error } = await client.webhooks.get("webhook-id");

if (!error) {
  console.log(data.name, data.url);
  console.log(data.last_successful_at);
  console.log(data.last_failure_at);
}
```

<Card title="API Reference" icon="book" href="/api-reference/webhooks/get-webhook">
  GET /webhooks/{webhook}
</Card>

## Update a Webhook

All fields are optional — only the ones you set are sent:

```typescript theme={null}
await client.webhooks.update("webhook-id", {
  url: "https://example.com/webhooks/lettr-v2",
  active: false,
  events: ["message.delivery"],
});
```

<Card title="API Reference" icon="book" href="/api-reference/webhooks/update-webhook">
  PATCH /webhooks/{webhook}
</Card>

## Delete a Webhook

```typescript theme={null}
const { error } = await client.webhooks.delete("webhook-id");
```

<Card title="API Reference" icon="book" href="/api-reference/webhooks/delete-webhook">
  DELETE /webhooks/{webhook}
</Card>

## What's Next

<CardGroup cols={2}>
  <Card title="Webhook Events" icon="bell" href="/learn/webhooks/introduction">
    Event types and payload format
  </Card>

  <Card title="Webhook Authorization" icon="shield-check" href="/learn/webhooks/authorization">
    Verify webhook authenticity
  </Card>
</CardGroup>
