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

# Register a webhook

> Registers a webhook subscription for an event type. Spirii generates the signing secret and returns it once in this response — store it securely, it is never shown again.



## OpenAPI

````yaml /openapi/emsp-webhook/openapi.yaml post /emsp/v1/webhooks
openapi: 3.0.0
info:
  title: Spirii EMSP - Webhook Management API
  description: Self-service registration and delivery of Spirii EMSP domain-event webhooks.
  version: v1
  contact: {}
servers:
  - url: https://api.spirii.com
    description: Production
security: []
tags:
  - name: Webhooks
    description: Webhook event management
paths:
  /emsp/v1/webhooks:
    post:
      tags:
        - Webhooks
      summary: Register a webhook
      description: >-
        Registers a webhook subscription for an event type. Spirii generates the
        signing secret and returns it once in this response — store it securely,
        it is never shown again.
      operationId: webhooks_register
      parameters:
        - name: Idempotency-Key
          in: header
          description: >-
            Client-generated unique key per operation intent (UUID). Same key +
            identical body replays the original response; same key + different
            body returns 409.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWebhookRequestDto'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookSubscriptionWithSecretDto'
        '400':
          description: Request validation failed
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetailDto'
        '422':
          description: Unknown event type
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetailDto'
components:
  schemas:
    CreateWebhookRequestDto:
      type: object
      properties:
        name:
          type: string
          maxLength: 255
          description: A name to help you recognise this subscription.
        description:
          type: string
          nullable: true
          maxLength: 1000
        url:
          type: string
          format: uri
          description: HTTPS endpoint that deliveries are POSTed to.
        event:
          type: string
          description: >-
            The event type to subscribe to. Must be a known type from GET
            /webhooks/event_types.
        api_version:
          type: string
          nullable: true
          maxLength: 50
          description: Pin a payload API version.
        custom_headers:
          type: object
          additionalProperties:
            type: string
          description: >-
            Custom headers sent with each delivery. Values are stored write-only
            and never returned.
      required:
        - name
        - url
        - event
    WebhookSubscriptionWithSecretDto:
      type: object
      properties:
        webhook_id:
          type: string
          format: uuid
          description: Platform-assigned stable identifier.
        name:
          type: string
          description: Human-readable name for the subscription.
        description:
          type: string
          nullable: true
        url:
          type: string
          format: uri
          description: HTTPS endpoint deliveries are POSTed to.
        event:
          type: string
          description: The event type this subscription receives.
        status:
          type: string
          enum:
            - ACTIVE
            - PAUSED
            - FAILED
        api_version:
          type: string
          nullable: true
          description: Pinned payload API version.
        custom_header_names:
          description: >-
            Names of configured custom headers. Header values are never
            returned.
          type: array
          items:
            type: string
        failure_count:
          type: number
          description: Consecutive delivery failures since the last success.
        last_failure_at:
          type: string
          format: date-time
          nullable: true
        last_success_at:
          type: string
          format: date-time
          nullable: true
        last_status_code:
          type: number
          nullable: true
        last_delivery_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        secret:
          type: string
          description: >-
            The signing secret. Shown only on creation and rotation — store it
            securely, it is never returned again.
      required:
        - webhook_id
        - name
        - url
        - event
        - status
        - custom_header_names
        - failure_count
        - created_at
        - updated_at
        - secret
    ProblemDetailDto:
      type: object
      properties:
        type:
          type: string
          example: about:blank
          description: >-
            URI identifying the problem type (about:blank until the docs site is
            live)
        title:
          type: string
          example: Tenant not found
        status:
          type: number
          example: 404
        detail:
          type: string
          example: No tenant exists with id 0192...c3.
        instance:
          type: string
          example: /v1/tenant/profile
        code:
          type: string
          example: tenant_not_found
          description: Stable machine-readable error code
        trace_id:
          type: string
          example: abc123def456
          description: Correlation id; matches dd.trace_id in Datadog
        timestamp:
          type: string
          example: '2026-06-10T09:30:00.000Z'
          format: date-time
        errors:
          description: Field-level validation errors (validation failures only)
          type: array
          items:
            $ref: '#/components/schemas/ProblemFieldErrorDto'
      required:
        - type
        - title
        - status
        - detail
        - instance
        - code
        - trace_id
        - timestamp
    ProblemFieldErrorDto:
      type: object
      properties:
        field:
          type: string
          example: workspace_id
        code:
          type: string
          example: is_uuid
        message:
          type: string
          example: workspace_id must be a UUID
      required:
        - field
        - code
        - message

````