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

# Run a simulation plan

> Deprecated: use POST /v1/simulation/run, which does the same thing and can also take the
plan configuration inline, so a one-off run does not have to create a plan first.

Creates and executes a job for an existing simulation run plan. Optionally provide runtime
variables to override plan-defined variables.



## OpenAPI

````yaml /api-reference/openapi.documented.json post /v1/simulation/plan/{planId}/job
openapi: 3.1.0
info:
  title: Roark Analytics API
  description: >-
    The Roark Analytics API gives you access to the same API that powers the
    award winning Roark Analytics platform.
  version: 1.0.0
servers:
  - description: Production
    url: https://api.roark.ai
security:
  - Bearer: []
tags:
  - name: Agent
  - name: Agent Endpoint
  - name: Call
  - name: Chat
  - name: Metric
  - name: Metric Policy
  - name: Metric Collection Job
  - name: Customer Flow
  - name: Customer Flow Edge Case
  - name: Simulation
  - name: Simulation Persona
  - name: Simulation Environment
  - name: Simulation Scenario
  - name: Simulation Run Plan
  - name: Simulation Template
  - name: Simulation Run Plan Job
  - name: Simulation Job
  - name: HTTP Request Definition
  - name: Webhook
  - name: Issue
  - name: Knowledge Base
  - name: Config
  - name: CLI Auth
  - name: Call Analysis
  - name: Health
paths:
  /v1/simulation/plan/{planId}/job:
    post:
      tags:
        - Simulation Run Plan Job
      summary: Run a simulation plan
      description: >-
        Deprecated: use POST /v1/simulation/run, which does the same thing and
        can also take the

        plan configuration inline, so a one-off run does not have to create a
        plan first.


        Creates and executes a job for an existing simulation run plan.
        Optionally provide runtime

        variables to override plan-defined variables.
      operationId: postV1SimulationPlanByPlanIdJob
      parameters:
        - in: path
          name: planId
          schema:
            type: string
            format: uuid
          required: true
          example: 7f3e4d2c-8a91-4b5c-9e6f-1a2b3c4d5e6f
          description: Simulation run plan ID
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunSimulationPlanBody'
      responses:
        '200':
          description: Successfully triggered simulation run plan
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/RunSimulationPlanResponse'
                required:
                  - data
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Validation error
              example:
                type: validation
                code: invalid_parameter
                message: The request was invalid
                param: email
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Authentication error
              example:
                type: authentication
                code: unauthorized
                message: Authentication required
          description: Unauthorized
        '402':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Insufficient credit
              example:
                type: payment_required
                code: insufficient_credits
                message: >-
                  Not enough credit to start this work. Add credit and try
                  again.
          description: Payment Required
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Permission error
              example:
                type: forbidden
                code: permission_denied
                message: You do not have permission to access this resource
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Not found error
              example:
                type: not_found
                code: resource_not_found
                message: The requested resource could not be found
          description: Simulation run plan not found
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Rate limit error
              example:
                type: rate_limit
                code: too_many_requests
                message: Rate limit exceeded
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Server error
              example:
                type: internal
                code: internal_error
                message: Internal server error
          description: Internal Server Error
      deprecated: true
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Roark from '@roarkanalytics/sdk';


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


            const response = await
            client.simulationRunPlanJob.start('7f3e4d2c-8a91-4b5c-9e6f-1a2b3c4d5e6f');


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

            client = Roark(
                bearer_token=os.environ.get("ROARK_API_BEARER_TOKEN"),  # This is the default and can be omitted
            )
            response = client.simulation_run_plan_job.start(
                plan_id="7f3e4d2c-8a91-4b5c-9e6f-1a2b3c4d5e6f",
            )
            print(response.data)
components:
  schemas:
    RunSimulationPlanBody:
      type: object
      properties:
        variables:
          anyOf:
            - type: object
              additionalProperties:
                type: string
              description: >-
                Global format: key-value pairs that apply to ALL scenarios in
                the plan
              example:
                orderNumber: '12345'
                environment: staging
            - type: array
              items:
                type: object
                properties:
                  flowId:
                    type: string
                    format: uuid
                    description: A customer flow this plan runs.
                  happyPath:
                    type: boolean
                    const: true
                    description: Narrow to the flow's happy path.
                  edgeCaseId:
                    type: string
                    format: uuid
                    description: Narrow to one edge case of that flow.
                  variables:
                    type: object
                    additionalProperties:
                      type: string
                    description: The values to apply.
                required:
                  - flowId
                  - variables
              description: Values scoped to the flows this plan runs
              example:
                - flowId: 550e8400-e29b-41d4-a716-446655440000
                  variables:
                    orderNumber: '12345'
                - flowId: 550e8400-e29b-41d4-a716-446655440000
                  happyPath: true
                  variables:
                    orderNumber: '55555'
                - flowId: 550e8400-e29b-41d4-a716-446655440000
                  edgeCaseId: 7a3d2e1f-c4b5-6a89-0d1e-2f3a4b5c6d7e
                  variables:
                    orderNumber: '67890'
            - type: array
              items:
                type: object
                properties:
                  scenarioId:
                    type: string
                    format: uuid
                    description: ID of the scenario to apply variables to
                  variables:
                    type: object
                    additionalProperties:
                      type: string
                    description: Key-value pairs for this scenario
                required:
                  - scenarioId
                  - variables
              deprecated: true
              description: >-
                Deprecated, for plans built on scenarios. Plans built on
                customer flows target them with `flowId` instead.
              example:
                - scenarioId: 550e8400-e29b-41d4-a716-446655440000
                  variables:
                    orderNumber: '12345'
                - scenarioId: 7a3d2e1f-c4b5-6a89-0d1e-2f3a4b5c6d7e
                  variables:
                    orderNumber: '67890'
          description: >-
            Values for the {{variables}} the run resolves, overriding whatever
            the plan has pinned.


            An object applies them to the whole run:

              { "orderNumber": "12345", "tier": "gold" }

            An array applies them per flow, or to just its happy path or one of
            its edge cases, when a single

            set will not do. Each entry carries what it applies to:

              [
                { "flowId": "550e8400-...", "variables": { "orderNumber": "12345" } },
                { "flowId": "550e8400-...", "happyPath": true, "variables": { "orderNumber": "55555" } },
                { "flowId": "550e8400-...", "edgeCaseId": "7a3d2e1f-...", "variables": { "orderNumber": "67890" } }
              ]

            An entry that narrows to neither covers everything that flow
            resolves. A flow this plan does not

            attach, or an edge case that does not belong to the flow, is
            rejected rather than ignored.


            A plan built on scenarios rather than customer flows targets them
            the same way, with `scenarioId` in

            place of `flowId`. That form is deprecated alongside scenarios
            themselves, and still accepted so runs

            against those plans keep working.
      description: >-
        Optional request body for running a simulation plan with runtime
        variables
    RunSimulationPlanResponse:
      type: object
      properties:
        simulationRunPlanId:
          type: string
          format: uuid
          description: ID of the simulation run plan that was executed
        simulationRunPlanJobId:
          type: string
          format: uuid
          description: ID of the simulation run plan job that was created
        status:
          type: string
          enum:
            - PENDING
            - QUEUED
            - CREATING_SNAPSHOTS
            - CREATING_SIMULATIONS
            - PREPARING_CAPACITY
            - RUNNING_SIMULATIONS
            - COMPLETED
            - FAILED
            - TIMED_OUT
            - CANCELLED
            - CANCELLING
            - ENDING_SIMULATIONS
          description: Initial status of the job
        createdAt:
          type: string
          description: When the job was created
      required:
        - simulationRunPlanId
        - simulationRunPlanJobId
        - status
        - createdAt
      description: Response when triggering a simulation run plan
      example:
        simulationRunPlanId: 9a8b7c6d-5e4f-3210-abcd-ef9876543210
        simulationRunPlanJobId: 7f3e4d2c-8a91-4b5c-9e6f-1a2b3c4d5e6f
        status: PENDING
        createdAt: '2024-01-15T10:30:00Z'
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          enum:
            - validation
            - authentication
            - forbidden
            - not_found
            - conflict
            - payment_required
            - rate_limit
            - internal
          description: The error type category
          examples:
            - validation
            - authentication
        code:
          type: string
          description: Machine-readable error code identifier
          examples:
            - invalid_parameter
            - missing_required_field
            - unauthorized
        message:
          type: string
          description: Human-readable error message
          examples:
            - The request was invalid
            - Authentication required
        param:
          type: string
          description: The parameter that caused the error (if applicable)
          examples:
            - email
            - user_id
        details:
          description: Additional error context information
      required:
        - type
        - code
        - message
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT

````