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

# Create a Webhook Subscription

> Creates a webhook subscription for the authenticated API user. A subscription may listen for one or more trigger values. Outbound requests default to POST when method is omitted. URL placeholders such as `{{id}}` and `{{metadata.us_state}}` are populated from each webhook payload. Optional headers are encrypted at rest and are not returned by the API.



## OpenAPI

````yaml /Sela_API.yaml post /api/webhooks/
openapi: 3.0.3
info:
  title: Sela API
  version: 1.0.2
  description: >-
    Create and manage leads, configure outbound webhook subscriptions, and use
    customer-specific lead ingestion workflows. Unless an endpoint says
    otherwise, authenticate with `Authorization: Token <api-key>`.
servers:
  - url: https://api.trysela.com/
    description: Production API
security: []
tags:
  - name: Leads
    description: Create, retrieve, update, and schedule customer leads.
  - name: Call Control
    description: Pause or resume outbound calling for an API user.
  - name: Lead Types
    description: >-
      Discover lead categories and the public metadata fields accepted for each
      one.
  - name: Webhooks
    description: >-
      Manage subscriptions that deliver lead and call events to customer
      systems.
  - name: Lead Ingestion
    description: >-
      Submit provider-specific lead payloads through ingestion URLs configured
      by Sela.
  - name: File Ingestion
    description: Request temporary upload URLs for configured CSV ingestion sources.
paths:
  /api/webhooks/:
    post:
      tags:
        - Webhooks
      summary: Create a Webhook Subscription
      description: >-
        Creates a webhook subscription for the authenticated API user. A
        subscription may listen for one or more trigger values. Outbound
        requests default to POST when method is omitted. URL placeholders such
        as `{{id}}` and `{{metadata.us_state}}` are populated from each webhook
        payload. Optional headers are encrypted at rest and are not returned by
        the API.
      operationId: webhooks_create
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookRequest'
            examples:
              CRMWebhook:
                value:
                  url: https://crm.example.com/leads/{{id}}/events
                  trigger:
                    - LEAD_CREATED
                    - CALL_COMPLETE
                  method: POST
                  filter_condition: get('last_chat.is_contact', False)
                  headers:
                    Authorization: Bearer <crm-api-token>
                summary: CRM webhook
                description: Send lead creation and completed-call events to a CRM.
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/WebhookRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/WebhookRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Webhook'
              examples:
                WebhookSubscriptionCreated:
                  value:
                    id: 42
                    url: https://crm.example.com/leads/{{id}}/events
                    trigger:
                      - LEAD_CREATED
                      - CALL_COMPLETE
                    method: POST
                    filter_condition: get('last_chat.is_contact', False)
                  summary: Webhook subscription created
          description: Webhook subscription created successfully.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookValidationErrorResponse'
              examples:
                InvalidTrigger:
                  value:
                    trigger:
                      - '"NOT_A_TRIGGER" is not a valid choice.'
                  summary: Invalid trigger
          description: >-
            The URL, triggers, filter expression, method, or headers are
            invalid.
        '401':
          description: API token is missing or invalid.
        '403':
          description: The API user does not have permission to create webhooks.
      security:
        - tokenAuth: []
      x-codeSamples:
        - lang: curl
          label: CRMWebhook
          source: |-
            curl --request POST \
              --url https://api.trysela.com/api/webhooks/ \
              --header 'Authorization: Token <api-key>' \
              --header 'Content-Type: application/json' \
              --data '{
                "url": "https://crm.example.com/leads/{{id}}/events",
                "trigger": [
                  "LEAD_CREATED",
                  "CALL_COMPLETE"
                ],
                "method": "POST",
                "filter_condition": "get('"'"'last_chat.is_contact'"'"', False)",
                "headers": {
                  "Authorization": "Bearer <crm-api-token>"
                }
              }'
components:
  schemas:
    WebhookRequest:
      type: object
      properties:
        url:
          type: string
          format: uri
          minLength: 1
          description: >-
            Webhook URL. Supports {{variable}} placeholders resolved from the
            webhook payload (e.g. https://api.example.com/leads/{{id}}/notify).
            Use dot notation for nested values (e.g. {{metadata.us_state}}).
          maxLength: 255
        trigger:
          type: array
          items:
            $ref: '#/components/schemas/TriggerEnum'
        method:
          nullable: true
          description: >-
            HTTP method to use when sending the webhook request. NULL or blank
            defaults to POST.


            * `GET` - GET

            * `POST` - POST

            * `PUT` - PUT

            * `PATCH` - PATCH
          oneOf:
            - $ref: '#/components/schemas/MethodEnum'
            - $ref: '#/components/schemas/BlankEnum'
            - $ref: '#/components/schemas/NullEnum'
        filter_condition:
          type: string
          nullable: true
          description: >-
            Optional filter expression that controls when the webhook fires. The
            expression is evaluated against the webhook payload - the same data
            sent in the request body. Leave blank to always fire. Use
            has('field') to check whether a field exists, get('path.to.value',
            default) for safe nested access, and comparison operators such as
            ==, !=, and, or. Examples: status == 'CLOSED', has('last_chat') and
            last_chat['is_contact'], get('last_chat.call_direction', '') ==
            'INBOUND'
        headers:
          type: object
          additionalProperties:
            type: string
          writeOnly: true
          description: >-
            Optional HTTP headers added to outbound webhook requests. Header
            values must be strings. Headers are accepted when creating a
            subscription but are never returned by the API.
      required:
        - url
    Webhook:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        url:
          type: string
          format: uri
          description: >-
            Webhook URL. Supports {{variable}} placeholders resolved from the
            webhook payload (e.g. https://api.example.com/leads/{{id}}/notify).
            Use dot notation for nested values (e.g. {{metadata.us_state}}).
          maxLength: 255
        trigger:
          type: array
          items:
            $ref: '#/components/schemas/TriggerEnum'
        method:
          nullable: true
          description: >-
            HTTP method to use when sending the webhook request. NULL or blank
            defaults to POST.


            * `GET` - GET

            * `POST` - POST

            * `PUT` - PUT

            * `PATCH` - PATCH
          oneOf:
            - $ref: '#/components/schemas/MethodEnum'
            - $ref: '#/components/schemas/BlankEnum'
            - $ref: '#/components/schemas/NullEnum'
        filter_condition:
          type: string
          nullable: true
          description: >-
            Optional filter expression that controls when the webhook fires. The
            expression is evaluated against the webhook payload - the same data
            sent in the request body. Leave blank to always fire. Use
            has('field') to check whether a field exists, get('path.to.value',
            default) for safe nested access, and comparison operators such as
            ==, !=, and, or. Examples: status == 'CLOSED', has('last_chat') and
            last_chat['is_contact'], get('last_chat.call_direction', '') ==
            'INBOUND'
      required:
        - id
        - url
    WebhookValidationErrorResponse:
      type: object
      properties:
        url:
          type: array
          items:
            type: string
        trigger:
          type: array
          items:
            type: string
        method:
          type: array
          items:
            type: string
        filter_condition:
          type: array
          items:
            type: string
        headers:
          type: array
          items:
            type: string
    TriggerEnum:
      type: string
      enum:
        - LEAD_CREATED
        - LEAD_UPDATED
        - LEAD_CLOSED
        - LEAD_CLOSED_INCOMPLETE
        - LEAD_LOST
        - LEAD_SCHEDULE_COMPLETED
        - LEAD_LATE_CALLBACK
        - LEAD_OUT_OF_TERRITORY
        - LEAD_BAD_NUMBER
        - LEAD_CANCELLED
        - LEAD_CALLBACK_TO_TRANSFER
        - LEAD_BEFORE_REENGAGEMENT
        - LEAD_REENGAGEMENT
        - LEAD_FIRST_INBOUND
        - CALL_COMPLETE
        - BEFORE_CALLING
        - CALL_FAILED
        - CALL_ENDED
        - CALL_TRANSFER_INITIATED
        - SMS_COMPLETE
        - SMS_DNC
        - CALL_DNC
    MethodEnum:
      enum:
        - GET
        - POST
        - PUT
        - PATCH
      type: string
      description: |-
        * `GET` - GET
        * `POST` - POST
        * `PUT` - PUT
        * `PATCH` - PATCH
    BlankEnum:
      enum:
        - ''
    NullEnum:
      enum:
        - null
  securitySchemes:
    tokenAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Token-based authentication with required prefix "Token"

````