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

# Create Webhook

> Create a new webhook.

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>

Once a webhook is created, events will be sent to it based on the criteria specified in the webhook.
The data sent follows the [Event schema](/api-reference/events-get) and is sent as a JSON array in the POST request in the `data` field. Below is an example request body:

```json theme={null}
{
  "data": [
    {
      "uuid": "b99b40c5-e306-4351-9f1d-9a13bb9e8bd1",
      "type": "track",
      "event": "ConnectedAccount",
      "userId": "123e4567-e89b-12d3-a456-426614174000",
      "properties": {
        "totalAccounts": 4
      },
      "timestamp": "2024-10-21T21:32:17.000Z",
      "parsedAt": "2024-10-21T21:32:23.194Z"
    }
  ]
}
```


## OpenAPI

````yaml post /webhooks
openapi: 3.0.0
info:
  title: trench API
  description: ''
  version: '1.0'
  contact: {}
servers: []
security: []
tags: []
paths:
  /webhooks:
    post:
      summary: Create a webhook
      operationId: WebhooksController_createWebhook
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookDTO'
      responses:
        '200':
          description: >-
            The webhook has been successfully created. Requires private API key
            in Bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Webhook'
      security:
        - bearer: []
components:
  schemas:
    WebhookDTO:
      type: object
      properties:
        url:
          type: string
          description: The URL that the webhook will send events to.
          example: https://your-webhook-url.com
        enableBatching:
          type: boolean
          description: Whether to enable batching for the webhook. Defaults to `false`.
          example: true
        eventTypes:
          description: >-
            The event types that the webhook will send. Defaults to `["*"] (all
            event types)`.
          example:
            - page
            - track
            - identify
            - group
          type: array
          items:
            type: string
        eventNames:
          description: >-
            The event names that the webhook will send. Defaults to `["*"] (all
            event names)`.
          example:
            - UserSignedUp
            - UserLoggedIn
          type: array
          items:
            type: string
        flatten:
          type: boolean
          description: >-
            Whether to flatten the event data. This is useful for downstream
            systems that don't support nested data structures. Defaults to
            `false`.
          example: true
      required:
        - url
    Webhook:
      type: object
      properties:
        uuid:
          type: string
          description: The UUID of the webhook. Automatically generated.
          example: 123e4567-e89b-12d3-a456-426614174000
        url:
          type: string
          description: The URL that the webhook will send events to.
          example: https://your-webhook-url.com
        enableBatching:
          type: boolean
          description: Whether to enable batching for the webhook.
          example: true
        createdAt:
          format: date-time
          type: string
          description: The date and time the webhook was created.
          example: '2021-01-01T00:00:00.000Z'
        eventTypes:
          description: >-
            The event types that the webhook will send. Use `*` to match all
            event types.
          example:
            - page
            - track
            - identify
            - group
          type: array
          items:
            type: string
        eventNames:
          description: >-
            The event names that the webhook will send. Use `*` to match all
            event names.
          example:
            - UserSignedUp
            - UserLoggedIn
          type: array
          items:
            type: string
        flatten:
          type: boolean
          description: >-
            Whether to flatten the event data. This is useful for downstream
            systems that don't support nested data structures.
          example: true
      required:
        - uuid
        - url
        - enableBatching
        - createdAt
        - eventTypes
        - eventNames
        - flatten

````