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

# Create Webhook

> Create a new webhook endpoint. Returns the webhook configuration including a secret for signature verification. The secret is only shown once. Requires API key with webhook:write.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/webhooks
openapi: 3.1.0
info:
  title: Migma.ai API (v1)
  description: >-
    API for managing brands, contacts, email generation, sending, and
    integrations.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.migma.ai
    description: Production
security:
  - apiKeyAuth: []
tags:
  - name: Projects/Brands
    description: Manage projects (brands) and import from websites
  - name: Contacts
    description: Manage your contacts, segments, tags, and topics
  - name: Segments
    description: Create and manage dynamic contact segments
  - name: Tags
    description: Organize contacts with tags
  - name: Topics
    description: Manage subscription topics and preferences
  - name: Emails
    description: Generate, send, and export emails
  - name: Email Validation
    description: Validate email content for compatibility and deliverability
  - name: Email Previews
    description: Preview emails across devices and email clients
  - name: Domains
    description: Manage sending domains and verification
  - name: Webhooks
    description: Manage webhook endpoints for real-time event notifications
  - name: Events
    description: Record customer events and conversions
  - name: Integrations
    description: Third-party platform integrations
  - name: Campaigns
    description: Create, schedule, send, and manage email campaigns
  - name: Project Editing
    description: Edit project assets, logos, images, and knowledge base entries
paths:
  /v1/webhooks:
    post:
      tags:
        - Webhooks
      summary: Create Webhook
      description: >-
        Create a new webhook endpoint. Returns the webhook configuration
        including a secret for signature verification. The secret is only shown
        once. Requires API key with webhook:write.
      operationId: CreateWebhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWebhookRequest'
      responses:
        '201':
          description: Webhook created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseWebhookCreated'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
      x-codeSamples:
        - lang: javascript
          label: Node.js SDK
          source: |-
            import Migma from 'migma';

            const migma = new Migma('YOUR_API_KEY');

            const { data, error } = await migma.webhooks.create({
              url: 'https://yourapp.com/webhooks/migma',
              events: ['email.generation.completed', 'subscriber.unsubscribed']
            });
components:
  schemas:
    CreateWebhookRequest:
      type: object
      properties:
        url:
          type: string
          format: uri
          description: The webhook endpoint URL (must be HTTPS)
        events:
          type: array
          items:
            type: string
          minItems: 1
          description: >-
            Array of event types to subscribe to (e.g.,
            email.generation.completed)
        description:
          type: string
          description: Optional description for the webhook
        customHeaders:
          type: object
          additionalProperties:
            type: string
          description: Optional custom headers to include in webhook requests
      required:
        - url
        - events
    ApiResponseWebhookCreated:
      allOf:
        - $ref: '#/components/schemas/ApiResponse'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/WebhookWithSecret'
    ApiResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          nullable: true
        error:
          type: string
          nullable: true
      required:
        - success
    WebhookWithSecret:
      allOf:
        - $ref: '#/components/schemas/Webhook'
        - type: object
          properties:
            secret:
              type: string
              description: >-
                Webhook secret for signature verification (only shown once upon
                creation)
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          default: false
        error:
          type: string
        code:
          type: string
          description: >-
            Machine-readable error code (e.g., IDEMPOTENCY_CONFLICT,
            DOMAIN_CLAIMABLE).
        data:
          type: object
          description: >-
            Additional structured context for the error, such as the affected
            domain.
          additionalProperties: true
      required:
        - success
        - error
    Webhook:
      type: object
      properties:
        id:
          type: string
          description: Webhook ID
        url:
          type: string
          format: uri
          description: The webhook endpoint URL
        events:
          type: array
          items:
            type: string
          description: Subscribed event types
        active:
          type: boolean
          description: Whether the webhook is active
        secretConfigured:
          type: boolean
          description: >-
            Whether a signing secret is configured. The secret value itself is
            returned only once, in the create response.
        description:
          type: string
          description: Optional description
        successCount:
          type: integer
          description: Number of successful deliveries
        failureCount:
          type: integer
          description: Number of failed deliveries
        lastTriggeredAt:
          type: string
          format: date-time
          description: Last trigger timestamp
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Use 'Authorization: Bearer YOUR_API_KEY' where
        YOUR_API_KEY is obtained from the Migma dashboard under Settings →
        Developers → API Keys.

````