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

# Get Workflow Schema

> Retrieve the full schema for a specific workflow version, including step definitions and required variables, using an OAuth access token.

## Endpoint

```
GET /v2/workflows/{workflow_id}/{version}/schema
```

## Authentication

This endpoint requires an OAuth access token. Send it as a bearer token:

```bash theme={null}
Authorization: Bearer your_access_token
```

**Required scope:** `workflows:read`

## Path Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `workflow_id` | string | Yes | Unique identifier for the workflow |
| `version` | string | Yes | Version number (e.g., "1") or "latest" for the most recent version |

## Request Example

```bash cURL theme={null}
curl -X GET "https://platform.chamelio.ai/v2/workflows/vendor_contract_review/latest/schema" \
  -H "Authorization: Bearer your_access_token"
```

```python Python theme={null}
import requests

workflow_id = "vendor_contract_review"
version = "latest"

url = f"https://platform.chamelio.ai/v2/workflows/{workflow_id}/{version}/schema"
headers = {
    "Authorization": "Bearer your_access_token"
}

response = requests.get(url, headers=headers)
print(response.json())
```

```javascript JavaScript theme={null}
const workflowId = 'vendor_contract_review';
const version = 'latest';

const response = await fetch(
  `https://platform.chamelio.ai/v2/workflows/${workflowId}/${version}/schema`,
  {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer your_access_token'
    }
  }
);

const data = await response.json();
console.log(data);
```

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "workflow_schema": {
    "workflow_id": "vendor_contract_review",
    "name": "Vendor Contract Review",
    "description": "Review and approve vendor contracts with automated checks",
    "latest_version": 3,
    "active": true,
    "intake_channels": ["manual"],
    "steps": [
      {
        "step_id": "intake_step",
        "step_type": "intake",
        "name": "Collect Contract Details",
        "description": "Collect contract and vendor information",
        "output_variables": [
          {
            "variable_type": "text",
            "variable_id": "vendor_name",
            "title": "Vendor Name",
            "description": "Name of the vendor"
          }
        ]
      },
      {
        "step_id": "approval_step",
        "step_type": "approval",
        "name": "Manager Approval",
        "description": "Manager reviews and approves or rejects",
        "output_variables": []
      }
    ],
    "all_variables": [
      {
        "variable_type": "text",
        "variable_id": "vendor_name",
        "title": "Vendor Name",
        "description": "Name of the vendor"
      }
    ],
    "init_variables": [
      {
        "variable_type": "text",
        "variable_id": "vendor_name",
        "title": "Vendor Name",
        "description": "Name of the vendor"
      },
      {
        "variable_type": "number_with_currency",
        "variable_id": "contract_value",
        "title": "Contract Value",
        "description": "Total contract value",
        "currencies": ["USD", "EUR", "GBP"],
        "default_currency": "USD"
      },
      {
        "variable_type": "dynamic_table",
        "variable_id": "line_items",
        "title": "Line Items",
        "description": "Products included in the contract",
        "columns": ["Item", "Quantity", "Unit Price"],
        "columns_metadata": [
          { "kind": "input", "name": "Item", "value_type": "text" },
          { "kind": "input", "name": "Quantity", "value_type": "number" },
          { "kind": "input", "name": "Unit Price", "value_type": "number_with_currency", "default_currency": "USD" }
        ]
      }
    ],
    "primary_object_names": null
  }
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `workflow_schema` | object | Complete workflow schema including its steps and variables |

### Workflow Schema Object

| Field | Type | Description |
| - | - | - |
| `workflow_id` | string | Unique identifier for the workflow |
| `name` | string | Human-readable workflow name |
| `description` | string | Description of what the workflow does |
| `latest_version` | integer | Version number of the returned workflow: the requested version, or the most recent one when `version` is `latest` |
| `active` | boolean | Whether the workflow is currently active |
| `intake_channels` | array | The channel the workflow's intake step collects requests from (for example, `manual`, `email`, `slack`). Empty when the workflow doesn't start with an intake step |
| `steps` | array | Workflow steps. See [Step Object Fields](#step-object-fields) |
| `all_variables` | array | Every variable produced by any step, deduplicated by `variable_id`. See [Variable Object Fields](#variable-object-fields) |
| `init_variables` | array | The variables you can set when initiating the workflow (the intake step's fields). Use these to build the `variables` for [Initiate Workflow](https://docs.chamelio.ai/api-reference/endpoint/v2/workflows/initiate.md) |
| `primary_object_names` | array or null | Primary object names configured on the intake step, or `null` when none are set |

### Step Object Fields

| Field | Type | Description |
| - | - | - |
| `step_id` | string | Unique identifier for the step |
| `step_type` | string | Step type, such as `intake`, `agent`, `review`, `approval`, `signature`, or `negotiate` |
| `name` | string | Human-readable step name |
| `description` | string | Description of what the step does |
| `output_variables` | array | Variables this step produces. Same shape as [Variable Object Fields](#variable-object-fields) |

### Variable Object Fields

Every variable includes these fields:

| Field | Type | Description |
| - | - | - |
| `variable_type` | string | Variable type, such as `text`, `number`, `number_with_currency`, `boolean`, `date`, `email`, `select`, `multi_select`, `dynamic_list`, `dynamic_table`, `file`, `multiple_files`, `user_entity`, or `business` |
| `variable_id` | string | Unique identifier for the variable. Use it as `variable_id` when initiating the workflow |
| `title` | string | Human-readable variable name |
| `description` | string or null | Description of what the variable represents |

Variables also include fields specific to their type, and may include other fields not listed here. The ones you need when initiating a workflow are:

| Variable type | Field | Type | Description |
| - | - | - | - |
| `select`, `multi_select` | `options` | array | Allowed option values |
| `file`, `multiple_files` | `accepted_file_types` | array | Accepted file extensions |
| `number_with_currency` | `currencies` | array or null | Currency codes the field accepts. `null` means any supported code |
| `number_with_currency` | `default_currency` | string or null | Currency applied when you send a plain amount |
| `dynamic_table` | `columns` | array | Column names, in order. List rows must follow this order and include one cell per column |
| `dynamic_table` | `columns_metadata` | array | Per-column details: `name`, `value_type` (`text`, `number`, `number_with_currency`, `boolean`, or `date`), `kind` (`input` or `formula`), and optional `default_currency`. Formula columns are calculated, so pass `null` for them in list rows |

## Error Responses

### 400 Bad Request

Returned when the version format is invalid, or when the access token has no user behind it.
`client_credentials` tokens act as the admin who created the application, so this applies only to
tokens issued before application creators were recorded.

```json theme={null}
{
  "detail": "Invalid version format: invalid_version"
}
```

```json theme={null}
{
  "detail": "client_credentials tokens are not associated with a user"
}
```

### 401 Unauthorized

Returned when the access token is missing, unknown, revoked, or expired, or when an `X-API-Key` was
sent instead of a bearer token. See [OAuth error responses](https://docs.chamelio.ai/api-reference/oauth-apps.md#error-responses).

```json theme={null}
{
  "detail": "Invalid access token"
}
```

### 403 Forbidden

Returned when the token lacks the required scope:

```json theme={null}
{
  "detail": "Insufficient scope; this endpoint requires: workflows:read"
}
```

Or when the user may not access this workflow:

```json theme={null}
{
  "detail": "You do not have access to this resource"
}
```

### 404 Not Found

Returned when the workflow or version does not exist.

```json theme={null}
{
  "detail": "Not found"
}
```

### 429 Too Many Requests

Returned when your organization exceeds its per-minute request limit.

```json theme={null}
{
  "detail": "Rate limit exceeded"
}
```

### 500 Internal Server Error

Returned when the request fails due to a server error.

```json theme={null}
{
  "detail": "Failed to get workflow schema"
}
```

## Notes

> [!NOTE]
>
> Use `"latest"` as the version to always get the most recent workflow schema without tracking version
> numbers.

> [!NOTE]
>
> The schema is fetched as the access token's user. A workflow the user cannot reach returns `403`
> rather than a schema.

> [!WARNING]
>
> Variable types and validation rules must be respected when initiating workflows. Validation failures
> result in a 422 error.

## Use Cases

This endpoint is useful for:

* **Form generation** - Dynamically create input forms based on workflow variables
* **Validation** - Validate user input before initiating workflows
* **Documentation** - Display workflow requirements to users
* **Integration planning** - Understand what data is needed to start a workflow
