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

# Create Webhook

> Register a webhook endpoint for real-time event notifications

## Method Signature

```typescript theme={null}
align.webhooks.create(data: CreateWebhookRequest): Promise<Webhook>
```

## Parameters

<ParamField body="url" type="string" required>
  HTTPS endpoint URL to receive webhook events.
</ParamField>

<Note>Webhooks subscribe to all supported events by default.</Note>

## Example

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import Align from "@tolbel/align";

    const align = new Align({
      apiKey: process.env.ALIGN_API_KEY!,
      environment: "sandbox",
    });

    const webhook = await align.webhooks.create({
      url: "https://your-app.com/webhooks/align",
    });

    console.log(`Webhook ID: ${webhook.id}`);
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const webhook = await align.webhooks.create({
      url: "https://your-app.com/webhooks/align",
    });

    console.log("Webhook ID:", webhook.id);
    ```
  </Tab>
</Tabs>

## Webhook Handler Example

Your webhook signature is signed using your **API Key**.

```typescript theme={null}
import express from "express";
import crypto from "crypto";

const app = express();

const API_KEY = process.env.ALIGN_API_KEY!;

app.post(
  "/webhooks/align",
  express.raw({ type: "application/json" }),
  (req, res) => {
    const signature = req.headers["x-hmac-signature"] as string;
    const payload = req.body.toString("utf8"); // Raw body

    // Verify signature using your API KEY
    const hmac = crypto.createHmac("sha256", API_KEY);
    const expectedSignature = hmac.update(payload).digest("hex");

    if (signature !== expectedSignature) {
      return res.status(401).send("Invalid signature");
    }

    const event = JSON.parse(payload);
    console.log("Received event:", event.event_type);

    res.status(200).send("OK");
  }
);
```

## Related Methods

<CardGroup cols={2}>
  <Card title="List Webhooks" icon="list" href="/docs/api/webhooks/list">
    View registered webhooks
  </Card>
</CardGroup>
