# Create Webhook

There are two ways to create webhooks in ZapSign: via the web interface or by calling the API endpoint. This allows you to configure webhooks in a flexible and efficient way, ensuring that your system is notified in real-time about important events.

{% hint style="info" %}
**Remember:** One webhook applies to all documents within your account. **It’s not necessary to create more than one webhook.** You will only need to perform the following setup once, not for each document.
{% endhint %}

#### In this section:

* [Creating webhooks via the web interface;](#creating-webhooks-via-web-interface)
* [Creating webhooks via the API;](#creating-webhooks-via-api)
* [Configuring Headers  for webhooks;](#configuring-headers-for-webhooks)

***

#### Creating webhooks via web interface

**Step 1:** In your account, go to **Settings > Integrations > ZapSign API > Webhooks**.

**Step 2:** Enter the endpoint (URL) of your server that will receive the webhook data. This endpoint must be ready to process POST requests and handle the JSON data that ZapSign will send.

**Step 3:** Choose which events you want to monitor. ZapSign allows you to select from five types of events:

* [Document Created](https://docs.zapsign.com.br/english/webhooks/eventos/document/doc_created)
* [Document Signed](https://docs.zapsign.com.br/english/webhooks/eventos/document/doc_signed)
* [Document Refused;](https://docs.zapsign.com.br/english/webhooks/eventos/document/doc_refused)
* [Document Deleted;](https://docs.zapsign.com.br/english/webhooks/eventos/document/doc_deleted)
* [Email Bounce;](https://docs.zapsign.com.br/english/webhooks/eventos/signer/email_bounce)
* [Doc Expired;](https://docs.zapsign.com.br/english/webhooks/eventos/document/doc-expired)

{% hint style="danger" %}
**The "All" option** only includes document-related events (created, signed, removed, and rejected). It does **not include the "Email Bounce" event (**&#x66;or email delivery failures). **To monitor that event, you will need to register it separately.**
{% endhint %}

**Step 4:** Configure whether you want to add a filter to receive notifications only for documents created from a specific template. Additionally, you can set up retry attempts in case a notification fails.

<figure><img src="https://1401277393-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4noMoX5ZGb2-RhWjjf-1703796690%2Fuploads%2F4VpvSyWj9TQww4l7kHjK%2Fimage.png?alt=media&#x26;token=236f64f2-0adc-48fd-8ca3-490e82206b6c" alt=""><figcaption></figcaption></figure>

***

### Creating webhooks via API

You can also create your endpoints via the API, adjusting the headers and events as needed for your workflow to ensure a seamless integration!

<figure><img src="https://1401277393-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4noMoX5ZGb2-RhWjjf-1703796690%2Fuploads%2FcB416PbDMDHzadZfIScV%2F5004862f-6c28-49c8-b75f-ebb66e5d7bf4.png?alt=media&#x26;token=b1e70151-44a6-4342-9b7a-c10e35785cc3" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Attention**: The "All" option includes only document events (created, signed, deleted, and refused). It does not include the "Email bounce" event (for email delivery failures). For this event, you need to register it separately.
{% endhint %}

## Create a webhook

<mark style="color:green;">`POST`</mark> `https://api.zapsign.com.br/api/v1/user/company/webhook/`

#### Headers

<table><thead><tr><th width="147.81536865234375">Name</th><th width="118.20953369140625">Type</th><th>Description</th></tr></thead><tbody><tr><td>Authorization<mark style="color:red;">*</mark></td><td>string</td><td><p>apiToken ahead of the "Bearer" text. </p><p>Ex: Bearer c7f35c84-7893-4087-b4fb-d1f06c23</p></td></tr></tbody></table>

#### Request Body

<table><thead><tr><th width="137.71234130859375">Name</th><th width="88.4901123046875">Type</th><th>Description</th></tr></thead><tbody><tr><td>url<mark style="color:red;">*</mark></td><td>string</td><td>Ex: <strong>”https://api.yoursite.com/webhook-zapsign/”</strong></td></tr><tr><td>type<mark style="color:red;">*</mark></td><td>string</td><td>Types of events you want to receive: "" (all) | "doc_signed" | "doc_created" | "doc_deleted"</td></tr><tr><td>doc_token</td><td>string</td><td>Document`s token to associate with. When defined, all the webhooks triggered will be for this document only.</td></tr><tr><td>headers</td><td>Array&#x3C;Header></td><td>Headers to be sent when the webhook is triggered. The configuration for each header is above</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK Webhook created successfully" %}

```
{
    "id": // Você receberá um ID de resposta//
}
```

{% endtab %}

{% tab title="403-Forbidden" %}

```
Make sure your API TOKEN is correct.
```

{% endtab %}
{% endtabs %}

***

### Configuring headers for webhooks

It is also possible to implement headers in webhooks, ensuring greater security in data transmission and optimizing performance between applications.<br>

**Webhook** - JSON root:

* **headers** - for each header:

  * **name (string) -** Name of the HTTP header to be sent.&#x20;

  &#x20;     **Ex:** Authorization

  * **value (string)** - Value of the HTTP header to be sent.&#x20;

  &#x20;     **Ex:** Bearer YOUR\_AUTHENTICATION\_TOKEN\
  \ <mark style="color:green;">`POST`</mark>` ``{{api_url}}/api/v1/user/company/webhook/header/`

```
{
    "id": {{webhook_id}},
    "headers": [
        {
            "name": "Authorization",
            "value": "Bearer YOUR_AUTHENTICATION_TOKEN"
        }
    ]
}

```

### Example of a request

{% embed url="<https://www.postman.com/zapsign/workspace/zapsign-workspace/request/27495556-3413e0f8-be2d-4161-9ffa-b449443dc68d?ctx=documentation>" %}
