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

# Create a new webhook

> Create a new webhook configuration for the repository



## OpenAPI

````yaml post /repos/{repo_id}/webhooks
openapi: 3.0.3
info:
  title: Diversion Core API
  description: >-
    Definition of the Core API used to access low-level functionality of
    Diversion
  version: 0.2.0
servers:
  - url: https://api.diversion.dev/v0
    description: Base endpoint
security: []
paths:
  /repos/{repo_id}/webhooks:
    parameters:
      - $ref: '#/components/parameters/RepoParam'
    post:
      tags:
        - Repository Webhook Management
      summary: Create a new webhook
      description: Create a new webhook configuration for the repository
      operationId: src.handlersv2.webhook.create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWebhookRequest'
      responses:
        '201':
          description: Webhook created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookConfiguration'
        '400':
          $ref: '#/components/responses/BadRequest'
        '409':
          description: Webhook with the same name already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        default:
          $ref: '#/components/responses/Error'
      security:
        - OAuth2:
            - coreapi/write
components:
  parameters:
    RepoParam:
      in: path
      name: repo_id
      required: true
      schema:
        type: string
        example: example_id
        minLength: 3
        maxLength: 128
      description: >-
        The repo ID of the repository. Repo _name_ can be used instead of the
        ID, but usage of ID for permanent linking and API requests is preferred.
  schemas:
    CreateWebhookRequest:
      type: object
      description: Request to create a new webhook
      properties:
        name:
          type: string
          description: User-friendly name for the webhook
          example: My CI/CD Webhook
          minLength: 1
          maxLength: 255
        description:
          type: string
          description: Optional description of the webhook
          maxLength: 1024
        endpoint_url:
          type: string
          format: uri
          description: The URL where webhook events will be sent
          example: https://api.example.com/webhooks/diversion
          maxLength: 2048
        secret:
          type: string
          description: >-
            Optional secret key used to generate HMAC signatures for webhook
            payload verification
          maxLength: 256
        events:
          $ref: '#/components/schemas/WebhookEventType'
        active:
          type: boolean
          description: Whether the webhook should be active
          default: true
        branches:
          type: array
          items:
            type: string
          description: >-
            Optional list of branch names to filter events for. If empty or not
            provided, events fire for all branches.
      required:
        - name
        - endpoint_url
        - events
    WebhookConfiguration:
      type: object
      description: A webhook configuration for a repository
      properties:
        id:
          type: string
          description: Unique identifier for the webhook
          example: dv.webhook.12345678-1234-1234-1234-123456789abc
        name:
          type: string
          description: User-friendly name for the webhook
          example: My CI/CD Webhook
          minLength: 1
          maxLength: 255
        description:
          type: string
          description: Optional description of the webhook
          maxLength: 1024
        endpoint_url:
          type: string
          format: uri
          description: The URL where webhook events will be sent
          example: https://api.example.com/webhooks/diversion
          maxLength: 2048
        events:
          $ref: '#/components/schemas/WebhookEventType'
        active:
          type: boolean
          description: Whether the webhook is active or not
          default: true
        secret:
          type: string
          description: >-
            The webhook secret for verifying signatures (only returned on
            creation)
          example: whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw
        created_unix:
          type: integer
          description: Unix timestamp when the webhook was created
          example: 1672531200
        updated_unix:
          type: integer
          description: Unix timestamp when the webhook was last updated
          example: 1672531200
        branches:
          type: array
          items:
            type: string
          description: >-
            Optional list of branch names to filter events for. If empty or not
            provided, events fire for all branches.
          example:
            - main
            - develop
      required:
        - id
        - name
        - endpoint_url
        - events
        - active
        - created_unix
        - updated_unix
    Error:
      type: object
      properties:
        status:
          type: integer
          description: HTTP status code
        detail:
          type: string
        title:
          type: string
        type:
          type: string
      required:
        - status
        - detail
    WebhookEventType:
      type: object
      description: >-
        Specifies which repository events will trigger HTTP POST requests to the
        webhook endpoint
      properties:
        commit_created:
          type: boolean
          default: false
          description: >-
            Trigger webhook when changes are committed to any branch in the
            repository
        merge_created:
          type: boolean
          default: false
          description: >-
            Trigger webhook when a merge is created in any branch in the
            repository
        review_created:
          type: boolean
          default: false
          description: Trigger webhook when a review is created in the repository
        review_merged:
          type: boolean
          default: false
          description: Trigger webhook when a review is merged in the repository
  responses:
    BadRequest:
      description: The request does not meet the required conditions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error:
      description: An error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    OAuth2:
      type: oauth2
      x-tokenInfoFunc: src.token_info.token_auth
      description: This API uses OAuth 2 with the implicit grant flow
      flows:
        implicit:
          authorizationUrl: https://auth.diversion.dev/oauth2/authorize
          scopes:
            coreapi/read: Operations with no possible side-effects
            coreapi/write: Modifying operations
            coreapi/admin: >-
              Organizational operations like adding a repo or changing repo
              properties

````