> ## Documentation Index
> Fetch the complete documentation index at: https://microstrate-1133-notifications-prefs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a new workflow

> Creates a new workflow for defining node sequences



## OpenAPI

````yaml /api-reference/endpoint/hub-flows/openapi.json post /hub/workflows
openapi: 3.0.0
info:
  title: quiva.ai Gateway
  description: API for managing collections, nodes, and workflows in quiva.ai Hub
  version: 0.1.0
  contact:
    name: quiva.ai Support
servers:
  - url: https://api.quiva.ai
    description: Production API server
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: Collections
    description: Operations related to collections
  - name: Nodes
    description: Operations related to nodes
  - name: Workflows
    description: Operations related to workflows
  - name: Oauth
    description: Oauth configurations and connections
paths:
  /hub/workflows:
    post:
      tags:
        - Workflows
      summary: Create a new workflow
      description: Creates a new workflow for defining node sequences
      operationId: createWorkflow
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWorkflowRequest'
            examples:
              simpleWorkflow:
                summary: Simple two-node workflow
                value:
                  name: MyWorkflow
                  collection: ms.hub.config.collection.workflow.1234567890
                  description: A workflow that processes data
                  config:
                    nodes:
                      - data:
                          id: start
                          name: Start
                          node_type: map
                          payload:
                            message: Start of workflow
                      - data:
                          id: process
                          name: Process
                          node_type: function
                          subject: quiva-function.process-function
                          payload:
                            input: '{start}'
                    edges:
                      - source: start
                        target: process
                        id: edge1
                    result: process
              conditionalWorkflow:
                summary: Workflow with conditional branching
                value:
                  name: ConditionalProcessing
                  collection: ms.hub.config.collection.workflow.9876543210
                  description: A workflow with conditional logic
                  config:
                    nodes:
                      - data:
                          id: input
                          name: Input Handler
                          node_type: map
                          payload:
                            data: '{trigger.body}'
                      - data:
                          id: check_type
                          name: Check Type
                          node_type: condition
                          payload:
                            condition: '{input.type} == ''premium'''
                      - data:
                          id: premium_handler
                          name: Premium Handler
                          node_type: function
                          subject: quiva-function.premium-processor
                          payload:
                            input: '{input}'
                      - data:
                          id: standard_handler
                          name: Standard Handler
                          node_type: function
                          subject: quiva-function.standard-processor
                          payload:
                            input: '{input}'
                    edges:
                      - source: input
                        target: check_type
                        id: e1
                      - source: check_type
                        target: premium_handler
                        id: e2
                        sourceHandle: 'true'
                      - source: check_type
                        target: standard_handler
                        id: e3
                        sourceHandle: 'false'
                    result: '{check_type} ? {premium_handler} : {standard_handler}'
              debouncedWorkflow:
                summary: Workflow with debouncing
                value:
                  name: DebouncedNotifications
                  collection: ms.hub.config.collection.workflow.5555555555
                  description: Debounces rapid notifications by user
                  config:
                    nodes:
                      - data:
                          id: aggregate
                          name: Aggregate Events
                          node_type: map
                          payload:
                            user_id: '{trigger.user_id}'
                            events: '{trigger.events}'
                      - data:
                          id: send_notification
                          name: Send Notification
                          node_type: function
                          subject: quiva-function.send-email
                          payload:
                            to: '{aggregate.user_id}'
                            body: '{aggregate.events}'
                    edges:
                      - source: aggregate
                        target: send_notification
                        id: e1
                    result: send_notification
                    options:
                      run_type: debounced
                      debounce_on: '{trigger.user_id}'
                      debounce_time: 5000
                      debounce_max: 30000
              evalWorkflow:
                summary: Workflow using eval node for calculations
                value:
                  name: PriceCalculator
                  collection: ms.hub.config.collection.workflow.7777777777
                  description: Calculates pricing with discounts
                  config:
                    nodes:
                      - data:
                          id: get_prices
                          name: Get Base Prices
                          node_type: function
                          subject: quiva-function.get-pricing
                          payload:
                            product_ids: '{trigger.products}'
                      - data:
                          id: calculate_total
                          name: Calculate Total
                          node_type: eval
                          payload:
                            code: >-
                              const prices = get_prices.items; const subtotal =
                              prices.reduce((sum, p) => sum + p.price *
                              p.quantity, 0); const discount =
                              trigger.discount_percent || 0; return { subtotal,
                              discount: subtotal * discount / 100, total:
                              subtotal * (1 - discount / 100) };
                    edges:
                      - source: get_prices
                        target: calculate_total
                        id: e1
                    result: calculate_total
              nestedFlowWorkflow:
                summary: Workflow calling another flow
                value:
                  name: OrderProcessor
                  collection: ms.hub.config.collection.workflow.8888888888
                  description: Processes orders by calling sub-workflows
                  config:
                    nodes:
                      - data:
                          id: validate
                          name: Validate Order
                          node_type: function
                          subject: quiva-function.validate-order
                          payload:
                            order: '{trigger.order}'
                      - data:
                          id: process_payment
                          name: Process Payment
                          node_type: flow
                          subject: ms.hub.config.workflow.8888888888.payment-flow
                          await: true
                          payload:
                            amount: '{validate.total}'
                            customer_id: '{trigger.customer_id}'
                      - data:
                          id: fulfill
                          name: Fulfill Order
                          node_type: flow
                          subject: ms.hub.config.workflow.8888888888.fulfillment-flow
                          await: false
                          payload:
                            order_id: '{validate.order_id}'
                            payment_ref: '{process_payment.reference}'
                    edges:
                      - source: validate
                        target: process_payment
                        id: e1
                      - source: process_payment
                        target: fulfill
                        id: e2
                    result: fulfill
              integrationWorkflow:
                summary: Workflow with external integration
                value:
                  name: SlackNotifier
                  collection: ms.hub.config.collection.workflow.3333333333
                  description: Sends notifications to Slack
                  config:
                    nodes:
                      - data:
                          id: format_message
                          name: Format Message
                          node_type: map
                          payload:
                            channel: '#alerts'
                            text: 'Alert: {trigger.message}'
                            blocks:
                              - type: section
                                text:
                                  type: mrkdwn
                                  text: |-
                                    *{trigger.title}*
                                    {trigger.message}
                      - data:
                          id: send_slack
                          name: Send to Slack
                          node_type: integration
                          subject: slack.chat.postMessage
                          payload: '{format_message}'
                          options:
                            timeout: 10000
                            attempts: 3
                            backoff_ms: 1000
                    edges:
                      - source: format_message
                        target: send_slack
                        id: e1
                    result: send_slack
      responses:
        '201':
          description: Workflow created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateWorkflowResponse'
              examples:
                simpleWorkflowCreated:
                  summary: Simple workflow created
                  value:
                    subject: ms.hub.config.workflow.draft.1234567890.98765432
                    name: MyWorkflow
                    collection: ms.hub.config.collection.workflow.1234567890
                    description: A workflow that processes data
                    config:
                      nodes:
                        - data:
                            id: start
                            name: Start
                            node_type: map
                            payload:
                              message: Start of workflow
                        - data:
                            id: process
                            name: Process
                            node_type: function
                            subject: quiva-function.process-function
                            payload:
                              input: '{start}'
                      edges:
                        - source: start
                          target: process
                          id: edge1
                      result: process
                    modified: 1651395678
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                NameRequired:
                  value:
                    error: a name is required
                CollectionRequired:
                  value:
                    error: a collection subject is required
                InvalidCollection:
                  value:
                    error: invalid collection subject
                InvalidNodeId:
                  value:
                    error: >-
                      invalid ID. An ID must start with a letter or underscore
                      and must contain only alphanumeric characters, hyphens and
                      underscores
                ReservedWord:
                  value:
                    error: cannot use a reserved word as a node id:trigger
                PayloadRequired:
                  value:
                    error: payload is required:nodeId
                FunctionSubjectRequired:
                  value:
                    error: a subject is required for the function:nodeId
                FlowSubjectRequired:
                  value:
                    error: a subject is required for the flow:nodeId
                DuplicateNodeId:
                  value:
                    error: duplicate node id found:nodeId
                EdgeSourceTargetRequired:
                  value:
                    error: 'source and target required on edge: source->target'
                SourceNodeNotFound:
                  value:
                    error: source node not found:source->target
                TargetNodeNotFound:
                  value:
                    error: target node not found:source->target
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                CollectionNotFound:
                  value:
                    error: collection not found
                FunctionNotFound:
                  value:
                    error: function not found
        '409':
          description: Workflow already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: >-
                  workflow
                  exists:ms.hub.config.workflow.draft.1234567890.98765432
components:
  schemas:
    CreateWorkflowRequest:
      type: object
      required:
        - name
        - collection
      properties:
        name:
          type: string
          description: Name of the workflow
        collection:
          type: string
          description: Subject of the collection this workflow belongs to
        description:
          type: string
          description: Optional description of the workflow
        config:
          $ref: '#/components/schemas/WorkflowConfig'
    CreateWorkflowResponse:
      type: object
      properties:
        subject:
          type: string
          description: Subject identifier for the workflow
        name:
          type: string
          description: Name of the workflow
        collection:
          type: string
          description: Subject of the collection this workflow belongs to
        description:
          type: string
          description: Description of the workflow
        config:
          $ref: '#/components/schemas/WorkflowConfig'
        modified:
          $ref: '#/components/schemas/Modified'
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
    WorkflowConfig:
      type: object
      properties:
        nodes:
          type: array
          items:
            type: object
            properties:
              data:
                $ref: '#/components/schemas/NodeData'
              position:
                type: object
                description: Visual position of the node in the workflow editor
              style:
                type: object
                description: Visual styling of the node
          description: Array of nodes in the workflow
        edges:
          type: array
          items:
            $ref: '#/components/schemas/Edge'
          description: Array of edges connecting nodes in the workflow
        static:
          type: object
          description: Static data available to all nodes in the workflow
        result:
          type: string
          description: Expression to determine the final result of the workflow
        options:
          type: object
          properties:
            run_type:
              type: string
              enum:
                - debounced
                - ordered
              description: Execution mode for the workflow
            order_on:
              type: string
              description: Field to order workflow executions by
            debounce_on:
              type: string
              description: Field to debounce workflow executions on
            debounce_time:
              type: integer
              description: Debounce time in milliseconds
            debounce_max:
              type: integer
              description: Maximum debounce time in milliseconds
    Modified:
      type: integer
      description: Timestamp of last modification
    NodeData:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the node
        name:
          type: string
          description: Name of the node
        description:
          type: string
          description: Description of the node
        node_type:
          type: string
          enum:
            - function
            - flow
            - condition
            - map
            - eval
            - integration
          description: >-
            ## Node Types


            ### 1. `function`

            **Definition**:  

            A **Hydra function node** used to provide a *subject* or perform a
            custom computation. It encapsulates reusable logic defined within
            the Hydra platform.


            ### 2. `flow`

            **Definition**:  

            A node that **invokes another flow**, either **synchronously** or
            **asynchronously**, enabling flow modularization and reuse.


            ### 3. `condition`

            **Definition**:  

            A **branching node** that evaluates a condition to determine the
            **flow of execution**, similar to `if`/`else` logic in programming.


            ### 4. `map`

            **Definition**:  

            A **data transformation node** used to **reshape or remap the
            payload**, allowing the flow to adapt the structure of data as it
            progresses.


            ### 5. `eval`

            **Definition**:  

            Executes **simple JavaScript code** to dynamically **evaluate
            expressions**, perform calculations, or manipulate data inline
            within the flow.


            ### 6. `integration`

            **Definition**:  

            Similar to a `function` node, but specifically tied to **predefined
            APIs**. It uses an HTTP-like interface and references **a known set
            of external services** managed by the platform.
        subject:
          type: string
          description: Subject identifier for function or flow node types
        payload:
          description: Payload data for the node
        response_map:
          description: Mapping for response transformation
        options:
          $ref: '#/components/schemas/NodeOptions'
        await:
          type: boolean
          description: Whether to wait for completion nad return the result
    Edge:
      type: object
      required:
        - source
        - target
      properties:
        source:
          type: string
          description: ID of the source node
        target:
          type: string
          description: ID of the target node
        id:
          type: string
          description: Optional unique identifier for the edge
        sourceHandle:
          type: string
          description: Optional source handle identifier
        targetHandle:
          type: string
          description: Optional target handle identifier
    NodeOptions:
      type: object
      description: Node execution options
      properties:
        flat_map:
          type: boolean
          description: Whether to flatten the response
        backoff_ms:
          type: integer
          format: int64
          description: >-
            Backoff duration in milliseconds - how long to wait before next
            attempt. Applies to function and flow nodes only.
        timeout:
          type: integer
          format: int64
          description: >-
            Timeout duration in milliseconds. Applies to function and flow nodes
            only.
        attempts:
          type: integer
          format: int32
          description: Number of retry attempts. Applies to function and flow nodes only.
        ignore_response_codes:
          type: array
          items:
            type: integer
          description: >-
            List of HTTP response codes to ignore. Applies to function nodes
            only.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT Authorization header using the Bearer scheme
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

````