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

# Cadastrar webhook

> Cadastra um endpoint HTTPS para receber notificações de eventos. A URL é testada com um POST no momento do cadastro. Guarde o `signatureSecret` retornado.

Cadastra um endpoint HTTPS para receber notificações de eventos. A URL é testada com um `POST` no momento do cadastro.

<Warning>
  Guarde o `signatureSecret` retornado — você precisa dele para [validar a assinatura](/webhooks/seguranca) de cada webhook recebido.
</Warning>

<Info>
  Veja todos os eventos disponíveis e seus payloads em [Webhooks › Eventos](/webhooks/eventos/transacoes).
</Info>


## OpenAPI

````yaml POST /v1/webhook
openapi: 3.0.3
info:
  title: API Ephra
  description: >-
    API REST para gerar cobranças (PIX, cartão e boleto), consultar transações e
    gerenciar webhooks.
  version: 1.0.0
servers:
  - url: https://api.ephra.io
    description: Servidor de produção
security:
  - bearerAuth: []
tags:
  - name: Autenticação
    description: Login e obtenção do token de acesso
  - name: Pagamentos
    description: Criação de cobranças PIX, cartão e boleto
  - name: Assinaturas
    description: Cobrança recorrente — iniciar, listar, consultar e cancelar assinaturas
  - name: Transações
    description: Consulta de transações
  - name: Webhooks
    description: Cadastro e gerenciamento de webhooks
paths:
  /v1/webhook:
    post:
      tags:
        - Webhooks
      summary: Cadastrar webhook
      description: >-
        Cadastra um endpoint HTTPS para receber notificações de eventos. A URL é
        testada com um POST no momento do cadastro. Guarde o `signatureSecret`
        retornado.
      operationId: createWebhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - url
                - events
              properties:
                url:
                  type: string
                  format: uri
                  example: https://seusite.com/webhooks/ephra
                events:
                  type: array
                  items:
                    $ref: '#/components/schemas/WebhookEvent'
                  example:
                    - transaction_created
                    - transaction_paid
                    - transaction_refunded
                name:
                  type: string
                  nullable: true
                  example: Produção
                isActive:
                  type: boolean
                  default: true
                productIds:
                  type: array
                  items:
                    type: string
                  description: Limita o webhook a produtos específicos. Omitido = todos.
      responses:
        '201':
          description: Webhook criado
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/Webhook'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    WebhookEvent:
      type: string
      enum:
        - transaction_created
        - transaction_paid
        - transaction_refunded
        - transaction_updated
        - transfer_created
        - transfer_completed
        - transfer_canceled
        - transfer_updated
        - infraction
        - card_declined
        - sale_lost
        - cart_abandoned
        - product_canceled
    Webhook:
      type: object
      properties:
        id:
          type: integer
          example: 42
        name:
          type: string
          nullable: true
          example: Produção
        isActive:
          type: boolean
          example: true
        signatureSecret:
          type: string
          example: a1b2c3...
        url:
          type: string
          example: https://seusite.com/webhooks/ephra
        events:
          type: array
          items:
            $ref: '#/components/schemas/WebhookEvent'
        productIds:
          type: array
          items:
            type: string
        createdAt:
          type: string
          example: '2026-06-03T12:00:00.000Z'
    Error:
      type: object
      properties:
        statusCode:
          type: integer
          example: 400
        error:
          type: string
          example: Bad Request
        message:
          type: string
          example: Mensagem descritiva do erro
  responses:
    BadRequest:
      description: Requisição inválida
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 400
            error: Bad Request
            message: Documento inválido para o tipo selecionado
    Unauthorized:
      description: Token ausente, inválido ou expirado
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 401
            error: Unauthorized
            message: Token inválido ou expirado
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````