## Create Webhook

**post** `/print-mail/v1/webhooks`

Create a Webhook.

### Body Parameters

- `enabledEvents: array of "letter.created" or "letter.updated" or "postcard.created" or 18 more`

  The list of event types this webhook listens for.

  - `"letter.created"`

  - `"letter.updated"`

  - `"postcard.created"`

  - `"postcard.updated"`

  - `"self_mailer.created"`

  - `"self_mailer.updated"`

  - `"cheque.created"`

  - `"cheque.updated"`

  - `"box.created"`

  - `"box.updated"`

  - `"snap_pack.created"`

  - `"snap_pack.updated"`

  - `"return_envelope_order.created"`

  - `"return_envelope_order.updated"`

  - `"tracker.visited"`

  - `"campaign.created"`

  - `"campaign.updated"`

  - `"virtual_mailbox_item.created"`

  - `"postal_statement.created"`

  - `"document.created"`

  - `"document.updated"`

- `url: string`

  An HTTPS URL that PostGrid can invoke for webhook deliveries.

- `description: optional string`

  An optional string describing this resource. Will be visible in the API and the dashboard.

- `metadata: optional map[unknown]`

  See the section on Metadata.

- `payloadFormat: optional "jwt" or "json"`

  The format in which a Webhook's event payload is delivered.

  - `"jwt"`

  - `"json"`

- `secret: optional string`

  A webhook signing secret with at least 20 non-whitespace characters.

### Returns

- `Webhook object { id, createdAt, enabled, 9 more }`

  - `id: string`

    A unique ID prefixed with webhook_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `enabled: boolean`

    Whether this webhook is enabled. Disabled webhooks are not triggered.

  - `enabledEvents: array of "letter.created" or "letter.updated" or "postcard.created" or 18 more`

    The list of event types this webhook listens for.

    - `"letter.created"`

    - `"letter.updated"`

    - `"postcard.created"`

    - `"postcard.updated"`

    - `"self_mailer.created"`

    - `"self_mailer.updated"`

    - `"cheque.created"`

    - `"cheque.updated"`

    - `"box.created"`

    - `"box.updated"`

    - `"snap_pack.created"`

    - `"snap_pack.updated"`

    - `"return_envelope_order.created"`

    - `"return_envelope_order.updated"`

    - `"tracker.visited"`

    - `"campaign.created"`

    - `"campaign.updated"`

    - `"virtual_mailbox_item.created"`

    - `"postal_statement.created"`

    - `"document.created"`

    - `"document.updated"`

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "webhook"`

    Always `webhook`.

    - `"webhook"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `url: string`

    An HTTPS URL that PostGrid can invoke for webhook deliveries.

  - `description: optional string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `metadata: optional map[unknown]`

    See the section on Metadata.

  - `payloadFormat: optional "jwt" or "json"`

    The format in which a Webhook's event payload is delivered.

    - `"jwt"`

    - `"json"`

  - `secret: optional string`

    A webhook signing secret with at least 20 non-whitespace characters.

### Example

```http
curl https://api.postgrid.com/print-mail/v1/webhooks \
    -H 'Content-Type: application/json' \
    -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \
    -d '{
          "enabledEvents": [
            "letter.created"
          ],
          "url": "https://example.com/postgrid-webhook"
        }'
```

#### Response

```json
{
  "id": "webhook_skN2ZTvFwS62oc5tJY1gzw",
  "object": "webhook",
  "live": false,
  "description": "Letter Created",
  "url": "https://example.com/postgrid-webhook",
  "enabledEvents": [
    "letter.created"
  ],
  "payloadFormat": "jwt",
  "enabled": true,
  "secret": "webhook_secret_xkNXtQ4jHevFdkTG3mSf1Q",
  "createdAt": "2022-02-16T18:37:02.048Z",
  "updatedAt": "2022-02-16T18:37:02.048Z"
}
```
