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

# Crear flow como borrador

> Crea un flow de automatización a partir de una descripción declarativa. El flow siempre se guarda como borrador y no envía nada hasta que se activa. Con validate_only, solo valida y devuelve el resumen, sin guardar. Requiere una clave API con el permiso write.



## OpenAPI

````yaml /openapi.es.json post /v1/flows
openapi: 3.1.0
info:
  title: API de Bevits
  version: 1.0.0
  description: >-
    API pública para consultar datos de CRM, compras y automatización de una
    organización de Bevits y crear automatizaciones como borrador para
    revisarlas y activarlas.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.bevits.com
    description: Producción
security:
  - bearerAuth: []
tags:
  - name: Sistema
    description: Disponibilidad de la API.
  - name: Identidad
    description: Identidad de la organización y de la clave API.
  - name: Clientes
    description: Clientes y sus relaciones.
  - name: Segmentos
    description: Segmentos de clientes.
  - name: Compras
    description: Compras importadas desde las integraciones.
  - name: Datos del CRM
    description: Etiquetas y definiciones de atributos.
  - name: Automatizaciones
    description: Flows de automatización.
  - name: Campañas
    description: Campañas de email.
paths:
  /v1/flows:
    post:
      tags:
        - Automatizaciones
      summary: Crear flow como borrador
      description: >-
        Crea un flow de automatización a partir de una descripción declarativa.
        El flow siempre se guarda como borrador y no envía nada hasta que se
        activa. Con validate_only, solo valida y devuelve el resumen, sin
        guardar. Requiere una clave API con el permiso write.
      operationId: createFlowDraft
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FlowSpec'
            example:
              name: Boleto a pagar
              trigger:
                platform: nuvemshop
                event: order_created
              start: is_boleto
              nodes:
                - key: is_boleto
                  type: condition
                  field: order.paymentMethod
                  operator: equals
                  value: boleto
                  if_true: wait_1_day
                - key: wait_1_day
                  type: wait
                  amount: 1
                  unit: days
                  next: still_pending
                - key: still_pending
                  type: condition
                  field: order.paymentStatus
                  operator: equals
                  value: pending
                  if_true: remind
                - key: remind
                  type: send_whatsapp
                  template_id: wtp_...
      responses:
        '200':
          $ref: '#/components/responses/FlowDraft'
        '400':
          $ref: '#/components/responses/InvalidBody'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/WriteScopeRequired'
        '409':
          $ref: '#/components/responses/IdempotencyConflict'
        '422':
          $ref: '#/components/responses/FlowValidationError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: >-
        Clave única de la operación. Repetir la misma clave con el mismo cuerpo
        devuelve la respuesta original en lugar de ejecutarla de nuevo.
      schema:
        type: string
  schemas:
    FlowSpec:
      type: object
      required:
        - name
        - trigger
        - start
        - nodes
      additionalProperties: false
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
        description:
          type: string
          maxLength: 2000
        trigger:
          type: object
          description: Disparador del flow, como aparece en el catálogo.
          required:
            - platform
            - event
          additionalProperties: false
          properties:
            platform:
              type: string
              example: nuvemshop
            event:
              type: string
              example: order_created
        start:
          $ref: '#/components/schemas/FlowNodeKey'
        nodes:
          type: array
          minItems: 1
          maxItems: 50
          items:
            oneOf:
              - $ref: '#/components/schemas/FlowConditionNode'
              - $ref: '#/components/schemas/FlowWaitNode'
              - $ref: '#/components/schemas/FlowMessageNode'
              - $ref: '#/components/schemas/FlowUpdateTagsNode'
              - $ref: '#/components/schemas/FlowCreateCouponNode'
        validate_only:
          type: boolean
          default: false
          description: >-
            Si es true, solo valida el flow y devuelve el resumen, sin guardar
            nada.
    FlowNodeKey:
      type: string
      description: >-
        Clave del bloque: letras minúsculas, números y guiones bajos, empezando
        por una letra.
      pattern: ^[a-z][a-z0-9_]{0,63}$
      example: wait_1_day
    FlowConditionNode:
      type: object
      description: Divide el camino según un campo de los datos del disparador.
      required:
        - key
        - type
        - field
        - operator
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/FlowNodeKey'
        type:
          type: string
          const: condition
        field:
          type: string
          example: order.paymentStatus
        operator:
          $ref: '#/components/schemas/FlowConditionOperator'
        value:
          description: Omítelo para is_empty e is_not_empty.
          type:
            - string
            - number
            - boolean
        if_true:
          $ref: '#/components/schemas/FlowNodeLink'
        if_false:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowWaitNode:
      type: object
      description: Pausa el flow.
      required:
        - key
        - type
        - amount
        - unit
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/FlowNodeKey'
        type:
          type: string
          const: wait
        amount:
          type: integer
          minimum: 1
          maximum: 10000
        unit:
          type: string
          enum:
            - minutes
            - hours
            - days
        next:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowMessageNode:
      type: object
      description: >-
        Envía una plantilla: send_whatsapp y send_whatsapp_unofficial usan wtp_,
        send_email usa etp_ y send_sms usa stp_.
      required:
        - key
        - type
        - template_id
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/FlowNodeKey'
        type:
          type: string
          enum:
            - send_whatsapp
            - send_whatsapp_unofficial
            - send_email
            - send_sms
        template_id:
          type: string
          description: ID devuelto en el listado de plantillas de mensaje.
        next:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowUpdateTagsNode:
      type: object
      description: Agrega o quita etiquetas del cliente.
      required:
        - key
        - type
        - action
        - tag_ids
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/FlowNodeKey'
        type:
          type: string
          const: update_tags
        action:
          type: string
          enum:
            - add
            - remove
        tag_ids:
          type: array
          minItems: 1
          maxItems: 20
          items:
            type: string
            pattern: ^tag_[A-Za-z0-9_-]+$
        next:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowCreateCouponNode:
      type: object
      description: >-
        Crea un cupón único para el cliente, disponible en los mensajes
        siguientes. Habilita condiciones coupon.* después de él.
      required:
        - key
        - type
        - discount_type
        - discount_value
        - valid_for_days
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/FlowNodeKey'
        type:
          type: string
          const: create_coupon
        discount_type:
          type: string
          enum:
            - percentage
            - fixed
        discount_value:
          type: number
          exclusiveMinimum: 0
          description: Porcentaje (hasta 100) o valor fijo del descuento.
        valid_for_days:
          type: integer
          minimum: 1
          maximum: 365
        code_prefix:
          type: string
          pattern: ^[A-Z0-9]{1,12}$
          description: Prefijo del código, con hasta 12 letras mayúsculas o números.
        next:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowDraft:
      type: object
      required:
        - object
        - validate_only
        - status
        - trigger
        - outline
        - warnings
        - next_step
      properties:
        object:
          type: string
          const: flow_draft
        validate_only:
          type: boolean
          description: true cuando el flow solo se validó; no se guardó nada.
        id:
          type: string
          pattern: ^flw_[A-Za-z0-9_-]+$
        status:
          type: string
          const: draft
        revision:
          type: string
          description: >-
            Revisión del borrador guardado. Envíala al activar el flow después
            de revisarlo.
        html_url:
          type: string
          format: uri
          description: Enlace del flow en el editor de Bevits, para revisarlo.
        trigger:
          type: object
          required:
            - platform
            - event
          properties:
            platform:
              type: string
            event:
              type: string
        outline:
          type: array
          description: Pasos del flow en lenguaje simple.
          items:
            type: string
        warnings:
          type: array
          description: >-
            Avisos que no impiden el borrador, como una plantilla de WhatsApp
            todavía en revisión por Meta.
          items:
            $ref: '#/components/schemas/FlowBuildIssue'
        next_step:
          type: string
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
    RateLimitErrorResponse:
      allOf:
        - $ref: '#/components/schemas/ErrorResponse'
        - type: object
          required:
            - retry_after
          properties:
            retry_after:
              type: integer
              minimum: 1
              description: Segundos antes de volver a intentarlo.
    FlowConditionOperator:
      type: string
      enum:
        - equals
        - not_equals
        - greater_than
        - less_than
        - greater_than_or_equal
        - less_than_or_equal
        - contains
        - not_contains
        - starts_with
        - ends_with
        - is_empty
        - is_not_empty
        - includes
        - not_includes
    FlowNodeLink:
      description: Clave del siguiente bloque. Omítela para terminar el camino.
      anyOf:
        - $ref: '#/components/schemas/FlowNodeKey'
        - type: 'null'
    FlowBuildIssue:
      type: object
      required:
        - code
        - path
        - message
      properties:
        code:
          type: string
        path:
          type: string
          description: Ruta en la descripción del flow, como nodes[2].field.
        node_key:
          type: string
        message:
          type: string
    Error:
      type: object
      required:
        - type
        - message
        - request_id
      properties:
        type:
          type: string
          enum:
            - authentication_error
            - conflict
            - internal_error
            - invalid_request
            - not_found
            - permission_denied
            - rate_limited
            - validation_error
        message:
          type: string
        param:
          type: string
        request_id:
          type: string
          pattern: ^req_[a-f0-9]{24}$
  responses:
    FlowDraft:
      description: Flow validado o guardado como borrador.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/FlowDraft'
    InvalidBody:
      description: >-
        Cuerpo de la solicitud ausente, que no es un objeto JSON, o parámetro de
        ruta inválido.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Clave API ausente, inválida, expirada o revocada.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: authentication_error
              message: Invalid API key.
              request_id: req_07f6cdc3c20249d6afcd90b4
    WriteScopeRequired:
      description: La clave API no tiene el permiso write.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: permission_denied
              message: This API key does not have the required "write" scope.
              param: scope
              request_id: req_07f6cdc3c20249d6afcd90b4
    IdempotencyConflict:
      description: La Idempotency-Key ya se usó con otro cuerpo de solicitud.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    FlowValidationError:
      description: >-
        El flow no se puede crear ni activar. El mensaje lista todos los
        problemas, cada uno con su ruta, la clave del bloque y las opciones
        válidas.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Límite de solicitudes superado.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitErrorResponse'
    InternalError:
      description: Error inesperado en el servidor.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  headers:
    RetryAfter:
      description: Segundos antes de volver a intentarlo.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: Límite total de la ventana actual.
      schema:
        type: integer
        example: 600
    RateLimitRemaining:
      description: Solicitudes restantes en la ventana actual.
      schema:
        type: integer
        example: 599
    RateLimitReset:
      description: Instante UTC en que termina la ventana actual.
      schema:
        type: string
        format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: bvt_live_...
      description: Clave API creada en la configuración de la organización.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.