> ## 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.

# Create flow as a draft

> Creates an automation flow from a declarative description. The flow is always saved as a draft and sends nothing until it is activated. With validate_only, it only validates and returns the outline, saving nothing. Requires an API key with the write scope.



## OpenAPI

````yaml /openapi.en.json post /v1/flows
openapi: 3.1.0
info:
  title: Bevits API
  version: 1.0.0
  description: >-
    Public API for querying CRM, purchase, and automation data from a Bevits
    organization and creating automations as drafts for review and activation.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.bevits.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: System
    description: API availability.
  - name: Identity
    description: Organization and API key identity.
  - name: Customers
    description: Customers and their relationships.
  - name: Segments
    description: Customer segments.
  - name: Purchases
    description: Purchases imported from integrations.
  - name: CRM data
    description: Tags and attribute definitions.
  - name: Automations
    description: Automation flows.
  - name: Campaigns
    description: Email campaigns.
paths:
  /v1/flows:
    post:
      tags:
        - Automations
      summary: Create flow as a draft
      description: >-
        Creates an automation flow from a declarative description. The flow is
        always saved as a draft and sends nothing until it is activated. With
        validate_only, it only validates and returns the outline, saving
        nothing. Requires an API key with the write scope.
      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: >-
        Unique key for the operation. Repeating the same key with the same body
        returns the original response instead of running it again.
      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: Flow trigger, as listed in the catalog.
          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: >-
            When true, only validates the flow and returns the outline, saving
            nothing.
    FlowNodeKey:
      type: string
      description: >-
        Block key: lowercase letters, digits, and underscores, starting with a
        letter.
      pattern: ^[a-z][a-z0-9_]{0,63}$
      example: wait_1_day
    FlowConditionNode:
      type: object
      description: Branches on a field of the trigger's data.
      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: Omit for is_empty and is_not_empty.
          type:
            - string
            - number
            - boolean
        if_true:
          $ref: '#/components/schemas/FlowNodeLink'
        if_false:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowWaitNode:
      type: object
      description: Pauses the 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: >-
        Sends a template: send_whatsapp and send_whatsapp_unofficial use wtp_,
        send_email uses etp_, and send_sms uses 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 returned by the message template listing.
        next:
          $ref: '#/components/schemas/FlowNodeLink'
    FlowUpdateTagsNode:
      type: object
      description: Adds or removes customer tags.
      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: >-
        Creates a unique coupon for the customer, available to later messages.
        Enables coupon.* conditions after it.
      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: Discount percentage (up to 100) or fixed amount.
        valid_for_days:
          type: integer
          minimum: 1
          maximum: 365
        code_prefix:
          type: string
          pattern: ^[A-Z0-9]{1,12}$
          description: Code prefix, up to 12 uppercase letters or digits.
        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 when the flow was only validated; nothing was saved.
        id:
          type: string
          pattern: ^flw_[A-Za-z0-9_-]+$
        status:
          type: string
          const: draft
        revision:
          type: string
          description: >-
            Revision of the saved draft. Send it when activating the flow after
            review.
        html_url:
          type: string
          format: uri
          description: Link to the flow in the Bevits editor, for review.
        trigger:
          type: object
          required:
            - platform
            - event
          properties:
            platform:
              type: string
            event:
              type: string
        outline:
          type: array
          description: Flow steps in plain language.
          items:
            type: string
        warnings:
          type: array
          description: >-
            Non-blocking warnings, such as a WhatsApp template still under
            review by 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: Seconds before retrying.
    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: Key of the next block. Omit it to end the path.
      anyOf:
        - $ref: '#/components/schemas/FlowNodeKey'
        - type: 'null'
    FlowBuildIssue:
      type: object
      required:
        - code
        - path
        - message
      properties:
        code:
          type: string
        path:
          type: string
          description: Path in the flow description, such as 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 validated or saved as a draft.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/FlowDraft'
    InvalidBody:
      description: >-
        Missing request body, a body that is not a JSON object, or an invalid
        route parameter.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing, invalid, expired, or revoked API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: authentication_error
              message: Invalid API key.
              request_id: req_07f6cdc3c20249d6afcd90b4
    WriteScopeRequired:
      description: The API key does not have the write scope.
      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: The Idempotency-Key was already used with a different request body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    FlowValidationError:
      description: >-
        The flow can't be created or activated. The message lists every problem,
        each with its path, block key, and valid options.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Request limit exceeded.
      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: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  headers:
    RetryAfter:
      description: Seconds before retrying.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: Total limit for the current window.
      schema:
        type: integer
        example: 600
    RateLimitRemaining:
      description: Requests remaining in the current window.
      schema:
        type: integer
        example: 599
    RateLimitReset:
      description: UTC instant when the current window ends.
      schema:
        type: string
        format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: bvt_live_...
      description: API key created in the organization settings.

````

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