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

# Criar automação

> Cria uma nova automação.



## OpenAPI

````yaml /automations-api/api-reference/openapi-automations.json post /v1/automations
openapi: 3.0.3
info:
  title: 'Notifique API v1: Automações e eventos'
  version: 1.0.0
  description: >-
    Definição de **eventos** (nome + schema opcional do `payload`),
    **automações** em grafo (gatilho por evento ou **mensagem recebida** em
    canal, delays, condições, inclusive com **`source: "message"`** no inbound,
    **`endFlow`** para encerrar um ramo, envios multicanal, atualização de
    contato, etc.) e **disparo** via `POST /v1/events/send`. Autenticação:
    `Authorization: Bearer sk_live_...` ou header `x-api-key`. Todos os corpos
    usam **camelCase**.


    **Escopos:** `events:read` | `events:write` | `automations:read` |
    `automations:write`. O motor de envio dos passos (`sendTemplate`, e-mails
    diretos, etc.) ainda exige as chaves de envio dos canais correspondentes.


    **Paginação:** query `page` (≥1, padrão 1) e `limit` (1 a 100, padrão 20),
    como strings ou números coerentes.


    **Workspace bloqueado** responde **402** com `Payment Required`.


    **Onboarding:** em qualquer rota `/v1`, se a conta ainda não concluiu o
    onboarding, o middleware responde **403** com `code: ONBOARDING_REQUIRED`
    (corpo semelhante aos outros 403).
servers:
  - url: https://api.notifique.dev
    description: Produção
security:
  - ntfAutoBearerAuth: []
  - ntfAutoApiKeyHeader: []
tags:
  - name: Eventos
    description: CRUD de definições de evento + disparo `POST /v1/events/send`.
  - name: Automações
    description: CRUD de automações, stop e listagem de runs.
  - name: Runs
    description: Histórico e detalhe de execuções (`AutomationRun` + passos).
paths:
  /v1/automations:
    post:
      tags:
        - Automações
      summary: Criar automação
      description: Cria uma nova automação.
      operationId: ntfAuto_createAutomation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NtfAuto_AutomationCreateBody'
      responses:
        '200':
          $ref: '#/components/responses/NtfAuto_AutomationCreate200'
        '400':
          $ref: '#/components/responses/NtfAuto_GraphOrBody400'
        '401':
          $ref: '#/components/responses/NtfAuto_401'
        '402':
          $ref: '#/components/responses/NtfAuto_402'
        '403':
          $ref: '#/components/responses/NtfAuto_403AutomationsWrite'
components:
  schemas:
    NtfAuto_AutomationCreateBody:
      type: object
      required:
        - name
        - graph
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
        status:
          type: string
          enum:
            - ENABLED
            - DISABLED
          default: DISABLED
        graph:
          $ref: '#/components/schemas/NtfAuto_AutomationGraph'
    NtfAuto_AutomationGraph:
      type: object
      required:
        - steps
        - connections
      properties:
        steps:
          type: array
          minItems: 2
          items:
            $ref: '#/components/schemas/NtfAuto_GraphStep'
        connections:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/NtfAuto_GraphConnection'
        nodeLayout:
          type: object
          additionalProperties:
            type: object
            required:
              - x
              - 'y'
            properties:
              x:
                type: number
              'y':
                type: number
          description: 'Opcional: posições do editor visual (`stepKey` → coordenadas).'
      description: >-
        Grafo acíclico (DAG) com exatamente um `trigger`. Arestas a partir de
        `condition` exigem `branch`: `true` | `false`.
    NtfAuto_AutomationCreateResponse:
      type: object
      required:
        - success
        - data
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          type: object
          required:
            - id
            - name
            - status
            - triggerEventName
            - graphVersion
            - createdAt
          properties:
            id:
              type: string
            name:
              type: string
            status:
              type: string
              enum:
                - ENABLED
                - DISABLED
            triggerEventName:
              type: string
            graphVersion:
              type: integer
            createdAt:
              type: string
              format: date-time
    NtfAuto_ErrorGraphValidation:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: string
          description: >-
            Mensagem detalhada (validação Zod concatena com `; ` em
            INVALID_GRAPH).
        code:
          type: string
          description: Código estável quando o grafo ou vínculo com evento falha.
          enum:
            - INVALID_GRAPH
            - DUPLICATE_STEP_KEY
            - TRIGGER_COUNT
            - UNKNOWN_STEP
            - CONDITION_BRANCHES
            - CONDITION_BRANCH_TAG
            - CONDITION_BRANCH_DUP
            - BRANCH_INVALID
            - TRIGGER_NOT_ROOT
            - GRAPH_CYCLE
            - UNREACHABLE_STEP
            - DELAY_INCOMPLETE
            - CONDITION_SOURCE
            - CONDITION_PROPERTY
            - CONDITION_OPERATOR
            - CONDITION_VALUE
            - SEND_TEMPLATE_ID
            - SEND_EMAIL_INCOMPLETE
            - SEND_WHATSAPP_INCOMPLETE
            - SEND_TEXT_INCOMPLETE
            - SEND_TELEGRAM_INCOMPLETE
            - SEND_PUSH_INCOMPLETE
            - UPDATE_CONTACT_EMPTY
            - UPDATE_CONTACT_FIELD
            - UPDATE_CONTACT_INTENT
            - UPDATE_CONTACT_CLEAR_CUSTOM
            - UPDATE_CONTACT_VALUE
            - CREATE_CONTACT_RECIPIENT
            - EVENT_NOT_REGISTERED
    NtfAuto_ErrorEnvelope401:
      type: object
      required:
        - success
        - error
        - message
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: string
          example: Unauthorized
        message:
          type: string
    NtfAuto_ErrorPaymentRequired:
      type: object
      required:
        - success
        - error
        - message
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: string
          enum:
            - Payment Required
        message:
          type: string
          example: Plan expired or suspended
    NtfAuto_ErrorForbiddenScope:
      type: object
      required:
        - success
        - error
        - message
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: string
          enum:
            - Forbidden
        message:
          type: string
    NtfAuto_GraphStep:
      oneOf:
        - $ref: '#/components/schemas/NtfAuto_StepTrigger'
        - $ref: '#/components/schemas/NtfAuto_StepDelay'
        - $ref: '#/components/schemas/NtfAuto_StepCondition'
        - $ref: '#/components/schemas/NtfAuto_StepSendTemplate'
        - $ref: '#/components/schemas/NtfAuto_StepSendEmail'
        - $ref: '#/components/schemas/NtfAuto_StepSendWhatsapp'
        - $ref: '#/components/schemas/NtfAuto_StepSendSms'
        - $ref: '#/components/schemas/NtfAuto_StepSendTelegram'
        - $ref: '#/components/schemas/NtfAuto_StepSendPush'
        - $ref: '#/components/schemas/NtfAuto_StepSendRcs'
        - $ref: '#/components/schemas/NtfAuto_StepUpdateContact'
        - $ref: '#/components/schemas/NtfAuto_StepDeleteContact'
        - $ref: '#/components/schemas/NtfAuto_StepCreateContact'
        - $ref: '#/components/schemas/NtfAuto_StepEndFlow'
      discriminator:
        propertyName: stepType
        mapping:
          trigger:
            $ref: '#/components/schemas/NtfAuto_StepTrigger'
          delay:
            $ref: '#/components/schemas/NtfAuto_StepDelay'
          condition:
            $ref: '#/components/schemas/NtfAuto_StepCondition'
          sendTemplate:
            $ref: '#/components/schemas/NtfAuto_StepSendTemplate'
          sendEmail:
            $ref: '#/components/schemas/NtfAuto_StepSendEmail'
          sendWhatsapp:
            $ref: '#/components/schemas/NtfAuto_StepSendWhatsapp'
          sendSms:
            $ref: '#/components/schemas/NtfAuto_StepSendSms'
          sendTelegram:
            $ref: '#/components/schemas/NtfAuto_StepSendTelegram'
          sendPush:
            $ref: '#/components/schemas/NtfAuto_StepSendPush'
          sendRcs:
            $ref: '#/components/schemas/NtfAuto_StepSendRcs'
          updateContact:
            $ref: '#/components/schemas/NtfAuto_StepUpdateContact'
          deleteContact:
            $ref: '#/components/schemas/NtfAuto_StepDeleteContact'
          createContact:
            $ref: '#/components/schemas/NtfAuto_StepCreateContact'
          endFlow:
            $ref: '#/components/schemas/NtfAuto_StepEndFlow'
    NtfAuto_GraphConnection:
      type: object
      required:
        - from
        - to
      properties:
        from:
          type: string
          minLength: 1
          maxLength: 128
        to:
          type: string
          minLength: 1
          maxLength: 128
        branch:
          type: string
          enum:
            - 'true'
            - 'false'
          description: Obrigatório apenas saindo de `condition`.
    NtfAuto_StepTrigger:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
          minLength: 1
          maxLength: 128
        stepType:
          type: string
          enum:
            - trigger
        config:
          type: object
          required:
            - eventName
          properties:
            eventName:
              type: string
              minLength: 1
              maxLength: 256
              description: Não pode começar com `notifique:` (case-insensitive).
    NtfAuto_StepDelay:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
          minLength: 1
          maxLength: 128
        stepType:
          type: string
          enum:
            - delay
        config:
          type: object
          required:
            - durationMs
          properties:
            durationMs:
              type: integer
              minimum: 0
              maximum: 2592000000
              description: >-
                Máximo 30 dias em ms. Para persistir: `durationMs` > 0 e não
                usar só `editorDraft`.
            editorPlaceholder:
              type: boolean
            editorDraft:
              type: boolean
    NtfAuto_StepCondition:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
          minLength: 1
          maxLength: 128
        stepType:
          type: string
          enum:
            - condition
        config:
          type: object
          required:
            - source
            - operator
          properties:
            source:
              type: string
              enum:
                - event
                - contact
                - message
              description: >-
                `event` ou `contact` quando o gatilho é evento da API. `message`
                é **obrigatório** quando o gatilho é mensagem recebida em canal
                (compara texto inbound: body → bodyPreview → preview).
            propertyKey:
              type: string
              maxLength: 256
              nullable: true
              description: >-
                Obrigatório para `source` `event` ou `contact`: path no payload
                (pontos permitidos) ou campo do contato. Omitir para `message`.
            operator:
              type: string
              enum:
                - equals
                - notEquals
                - exists
                - isEmpty
                - contains
                - startsWith
                - endsWith
                - gt
                - lt
                - gte
                - lte
            compareValue:
              type: string
              nullable: true
              description: >-
                Obrigatório (não vazio) para operadores exceto `exists` e
                `isEmpty`. Para `gt`, `lt`, `gte` e `lte`, o valor da esquerda e
                o `compareValue` são interpretados como números (string numérica
                ou número JSON); se algum não for número finito, a condição é
                falsa.
    NtfAuto_StepSendTemplate:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendTemplate
        config:
          type: object
          required:
            - templateId
            - channels
          properties:
            templateId:
              type: string
            channels:
              type: array
              minItems: 1
              items:
                type: string
                enum:
                  - whatsapp
                  - sms
                  - email
                  - telegram
            fromEmail:
              type: string
              nullable: true
            instanceId:
              type: string
              nullable: true
            telegramInstanceId:
              type: string
              nullable: true
            variables:
              type: object
              additionalProperties:
                type: string
    NtfAuto_StepSendEmail:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendEmail
        config:
          type: object
          required:
            - subject
            - htmlBody
          properties:
            subject:
              type: string
              maxLength: 512
            htmlBody:
              type: string
              maxLength: 100000
            fromEmail:
              type: string
              nullable: true
    NtfAuto_StepSendWhatsapp:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendWhatsapp
        config:
          type: object
          required:
            - instanceId
            - body
          properties:
            instanceId:
              type: string
            body:
              type: string
              maxLength: 8192
    NtfAuto_StepSendSms:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendSms
        config:
          type: object
          required:
            - body
          properties:
            body:
              type: string
              maxLength: 2000
    NtfAuto_StepSendTelegram:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendTelegram
        config:
          type: object
          required:
            - instanceId
            - body
          properties:
            instanceId:
              type: string
            body:
              type: string
              maxLength: 8192
    NtfAuto_StepSendPush:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendPush
        config:
          type: object
          required:
            - pushAppId
            - title
            - body
          properties:
            pushAppId:
              type: string
            title:
              type: string
              maxLength: 256
            body:
              type: string
              maxLength: 4096
            url:
              type: string
              nullable: true
    NtfAuto_StepSendRcs:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - sendRcs
        config:
          type: object
          required:
            - body
          properties:
            body:
              type: string
              maxLength: 4096
    NtfAuto_StepUpdateContact:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - updateContact
        config:
          type: object
          properties:
            name:
              type: string
              nullable: true
            email:
              type: string
              nullable: true
            phone:
              type: string
              nullable: true
            url:
              type: string
              nullable: true
            custom:
              type: object
              additionalProperties:
                type: string
            actions:
              type: array
              maxItems: 50
              items:
                $ref: '#/components/schemas/NtfAuto_UpdateContactAction'
              description: >-
                Lista preferida. Se presente e não vazia, validação extra
                aplica-se (não misturar `clear` com `custom:`).
          description: 'Legado: campos planos + `custom`. Novo fluxo: `actions`.'
    NtfAuto_StepDeleteContact:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - deleteContact
        config:
          type: object
          additionalProperties: false
    NtfAuto_StepCreateContact:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
        stepType:
          type: string
          enum:
            - createContact
        config:
          type: object
          properties:
            name:
              type: string
              nullable: true
            email:
              type: string
              nullable: true
            phone:
              type: string
              nullable: true
          description: Pelo menos um de `email` ou `phone` não vazio após trim.
    NtfAuto_StepEndFlow:
      type: object
      required:
        - stepKey
        - stepType
        - config
      properties:
        stepKey:
          type: string
          minLength: 1
          maxLength: 128
        stepType:
          type: string
          enum:
            - endFlow
        config:
          type: object
          description: >-
            Terminator: no outgoing connections; engine completes with no side
            effects.
          additionalProperties: false
    NtfAuto_UpdateContactAction:
      type: object
      required:
        - fieldKey
        - intent
      properties:
        fieldKey:
          type: string
          minLength: 1
          maxLength: 128
          description: >-
            `name` | `email` | `phone` | `url` | `custom:chave`. Com `intent:
            clear`, não use `custom:`.
        intent:
          type: string
          enum:
            - clear
            - set
        literal:
          type: string
          nullable: true
          description: Valor fixo ou placeholders; usado com `set`.
        eventPath:
          type: string
          nullable: true
          description: Chave no payload do evento (com `set`).
  responses:
    NtfAuto_AutomationCreate200:
      description: Criada (resposta sem `graphJson`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NtfAuto_AutomationCreateResponse'
    NtfAuto_GraphOrBody400:
      description: >-
        `name` vazio ou grafo inválido. Em erros de grafo, `error` traz a
        **mensagem** detalhada e `code` o código estável.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NtfAuto_ErrorGraphValidation'
          examples:
            nameRequired:
              value:
                success: false
                error: Bad Request
                message: name is required
                code: BAD_REQUEST
            eventNotRegistered:
              value:
                success: false
                error: >-
                  Register an automation event named "user.created" before using
                  it in a trigger
                code: EVENT_NOT_REGISTERED
                message: >-
                  Register an automation event named "user.created" before using
                  it in a trigger
            invalidGraph:
              value:
                success: false
                error: Required; Required
                code: INVALID_GRAPH
                message: Required; Required
            cycle:
              value:
                success: false
                error: Automation graph must be acyclic (DAG)
                code: GRAPH_CYCLE
                message: Automation graph must be acyclic (DAG)
    NtfAuto_401:
      description: >-
        Chave ausente ou inválida. No middleware global de `/v1` também ocorre
        quando não há API Key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NtfAuto_ErrorEnvelope401'
          examples:
            route:
              value:
                success: false
                error: Unauthorized
                message: Invalid or missing API Key
                code: UNAUTHORIZED
            middleware:
              value:
                success: false
                error: Unauthorized
                message: >-
                  API Key is required. Provide Authorization: Bearer <key> or
                  x-api-key header.
                code: UNAUTHORIZED
    NtfAuto_402:
      description: Plano expirado ou workspace suspenso.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NtfAuto_ErrorPaymentRequired'
          example:
            success: false
            error: Payment Required
            message: Plan expired or suspended
            code: WORKSPACE_BLOCKED
    NtfAuto_403AutomationsWrite:
      description: Sem escopo `automations:write`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NtfAuto_ErrorForbiddenScope'
          example:
            success: false
            error: Forbidden
            message: 'Missing scope: automations:write'
            code: FORBIDDEN
  securitySchemes:
    ntfAutoBearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: '`Authorization: Bearer sk_live_...`'
    ntfAutoApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: Mesmo valor da chave, sem prefixo Bearer.

````