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

# Add an action to a flow

> Append a single action to a flow at the given `position`, optionally nesting it under a `parentFlowActionId` or supplying its own `children`. Supports a `nameOverride`, param `overrides`, and `continueOnError`. Returns 404 if the flow does not exist.

Supports an optional `Idempotency-Key` header (1-255 printable ASCII characters). Replays with the same key and an identical body return the original 201; a changed body under the same key returns 422 `idempotency_key_reused`.



## OpenAPI

````yaml /api-reference/workflows/flows.yaml post /flows/{flowId}/actions
openapi: 3.1.0
info:
  title: Flows
  version: v1
servers:
  - description: Droidrun Cloud API
    url: https://api.mobilerun.ai/v1
security:
  - bearerAuth: []
paths:
  /flows/{flowId}/actions:
    post:
      tags:
        - Flows
      summary: Add an action to a flow
      description: >-
        Append a single action to a flow at the given `position`, optionally
        nesting it under a `parentFlowActionId` or supplying its own `children`.
        Supports a `nameOverride`, param `overrides`, and `continueOnError`.
        Returns 404 if the flow does not exist.


        Supports an optional `Idempotency-Key` header (1-255 printable ASCII
        characters). Replays with the same key and an identical body return the
        original 201; a changed body under the same key returns 422
        `idempotency_key_reused`.
      operationId: addFlowAction
      parameters:
        - in: path
          name: flowId
          required: true
          schema:
            format: uuid
            type: string
        - description: >-
            Idempotency-Key: 1-255 printable ASCII characters. Same key with a
            different request body is a 422 idempotency_key_reused. A retryable
            in-flight duplicate is a 409 with Retry-After and x-should-retry:
            true; a terminal duplicate is a 409 with x-should-retry: false. A
            replay returns the current resource state with Idempotent-Replayed:
            true.
          in: header
          name: idempotency-key
          required: false
          schema:
            description: >-
              Idempotency-Key: 1-255 printable ASCII characters. Same key with a
              different request body is a 422 idempotency_key_reused. A
              retryable in-flight duplicate is a 409 with Retry-After and
              x-should-retry: true; a terminal duplicate is a 409 with
              x-should-retry: false. A replay returns the current resource state
              with Idempotent-Replayed: true.
            example: b3f6a9f0-6f1a-4e9a-9e7a-9c9b6b6a5a3f
            maxLength: 255
            minLength: 1
            pattern: ^[\x21-\x7E]{1,255}$
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddFlowActionBody'
      responses:
        '201':
          content:
            application/json:
              schema:
                properties:
                  data:
                    $ref: '#/components/schemas/FlowAction'
                required:
                  - data
                type: object
          description: Flow action added
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlowTemplateReferenceInvalidError'
          description: Template reference validation failed
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlowNotFoundError'
          description: Flow not found
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Mobilerun from '@mobilerun/sdk';


            const client = new Mobilerun({
              apiKey: process.env['MOBILERUN_CLOUD_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.workflows.flows.actions.add('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
            {
              actionId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
              position: 0,
            });


            console.log(response.data);
        - lang: Python
          source: |-
            import os
            from mobilerun_sdk import Mobilerun

            client = Mobilerun(
                api_key=os.environ.get("MOBILERUN_CLOUD_API_KEY"),  # This is the default and can be omitted
            )
            response = client.workflows.flows.actions.add(
                flow_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                action_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                position=0,
            )
            print(response.data)
components:
  schemas:
    AddFlowActionBody:
      additionalProperties: false
      properties:
        actionId:
          format: uuid
          type: string
        children:
          items:
            $ref: '#/components/schemas/FlowChildActionInput'
          type: array
        continueOnError:
          default: false
          type: boolean
        key:
          description: >-
            Stable identifier used by template resolution v2+ to address this
            step as {{key.field}}. Omitted keys are derived from the step name
            whenever a flow is created. For template resolution v3, replacing an
            existing flow's full action tree requires every step to carry an
            explicit key — a missing key is rejected there, not derived, so a
            name change can never silently move a step's key.
          pattern: ^[a-z_][a-z0-9_-]{0,63}$
          type: string
        nameOverride:
          maxLength: 256
          minLength: 1
          type: string
        overrides:
          $ref: '#/components/schemas/FlowActionOverrides'
        parentFlowActionId:
          format: uuid
          type:
            - string
            - 'null'
        position:
          minimum: 0
          type: integer
        recordingEnabled:
          default: false
          type: boolean
      required:
        - actionId
        - position
      type: object
    FlowAction:
      properties:
        actionId:
          format: uuid
          type: string
        continueOnError:
          type: boolean
        createdAt:
          format: date-time
          type:
            - string
            - 'null'
        flowId:
          format: uuid
          type: string
        id:
          format: uuid
          type: string
        key:
          type: string
        nameOverride:
          type:
            - string
            - 'null'
        overrides:
          properties:
            params:
              additionalProperties: {}
              type: object
          type:
            - object
            - 'null'
        parentFlowActionId:
          format: uuid
          type:
            - string
            - 'null'
        position:
          type: integer
        recordingEnabled:
          description: >-
            Selected for per-step recording under the flow's "selected_steps"
            recording policy.
          type: boolean
      required:
        - id
        - flowId
        - actionId
        - parentFlowActionId
        - position
        - continueOnError
        - nameOverride
        - key
        - overrides
        - recordingEnabled
        - createdAt
      type: object
    FlowTemplateReferenceInvalidError:
      properties:
        code:
          enum:
            - template_reference_invalid
          type: string
        details:
          items:
            properties:
              field:
                type: string
              knownSteps:
                items:
                  type: string
                maxItems: 30
                type: array
              message:
                type: string
              reference:
                type: string
            required:
              - field
              - message
            type: object
          type: array
        message:
          enum:
            - Template reference validation failed
          type: string
      required:
        - code
        - message
        - details
      type: object
    FlowNotFoundError:
      properties:
        code:
          enum:
            - flow_not_found
          type: string
        message:
          type: string
      required:
        - code
        - message
      type: object
    FlowChildActionInput:
      additionalProperties: false
      properties:
        actionId:
          format: uuid
          type: string
        continueOnError:
          default: false
          type: boolean
        key:
          description: >-
            Stable identifier used by template resolution v2+ to address this
            step as {{key.field}}. Omitted keys are derived from the step name
            whenever a flow is created. For template resolution v3, replacing an
            existing flow's full action tree requires every step to carry an
            explicit key — a missing key is rejected there, not derived, so a
            name change can never silently move a step's key.
          pattern: ^[a-z_][a-z0-9_-]{0,63}$
          type: string
        nameOverride:
          maxLength: 256
          minLength: 1
          type: string
        overrides:
          $ref: '#/components/schemas/FlowActionOverrides'
        position:
          minimum: 0
          type: integer
        recordingEnabled:
          default: false
          type: boolean
      required:
        - actionId
        - position
      type: object
    FlowActionOverrides:
      additionalProperties: false
      properties:
        params:
          additionalProperties: {}
          type: object
      type:
        - object
        - 'null'
  securitySchemes:
    bearerAuth:
      bearerFormat: Opaque
      description: Bearer token via Authorization header
      scheme: bearer
      type: http

````

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