> ## 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 complete schema for a specific workflow version

## Endpoint

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

## Authentication

This endpoint requires authentication via API key. Include your API key in the `X-API-Key` header:

```bash theme={null}
X-API-Key: ca_your_api_key_here
```

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

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://platform.chamelio.ai/workflows/vendor_contract_review/latest/schema" \
    -H "X-API-Key: ca_your_api_key_here"
  ```

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

  workflow_id = "vendor_contract_review"
  version = "latest"

  url = f"https://platform.chamelio.ai/workflows/{workflow_id}/{version}/schema"
  headers = {
      "X-API-Key": "ca_your_api_key_here"
  }

  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/workflows/${workflowId}/${version}/schema`,
    {
      method: 'GET',
      headers: {
        'X-API-Key': 'ca_your_api_key_here'
      }
    }
  );

  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "workflow_schema": {
    "workflow_id": "vendor_contract_review",
    "workflow_name": "Vendor Contract Review",
    "version": 1,
    "description": "Review and approve vendor contracts with automated checks",
    "is_active": true,
    "variables": [
      {
        "variable_id": "contract_file",
        "variable_name": "Contract Document",
        "type": "file",
        "required": true,
        "description": "The vendor contract to review",
        "validation": {
          "allowed_extensions": ["pdf", "docx"]
        }
      },
      {
        "variable_id": "vendor_name",
        "variable_name": "Vendor Name",
        "type": "text",
        "required": true,
        "description": "Name of the vendor"
      },
      {
        "variable_id": "contract_value",
        "variable_name": "Contract Value",
        "type": "number",
        "required": true,
        "description": "Total contract value in USD"
      },
      {
        "variable_id": "reviewer_email",
        "variable_name": "Reviewer",
        "type": "email",
        "required": true,
        "description": "Email of the person who will review"
      }
    ],
    "steps": [
      {
        "step_id": "intake_step",
        "step_name": "Collect Contract Details",
        "step_type": "intake",
        "description": "Collect contract and vendor information"
      },
      {
        "step_id": "review_step",
        "step_name": "AI Review",
        "step_type": "agent",
        "description": "AI analyzes contract for risks and compliance"
      },
      {
        "step_id": "approval_step",
        "step_name": "Manager Approval",
        "step_type": "approval",
        "description": "Manager reviews and approves or rejects"
      }
    ]
  }
}
```

### Response Fields

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

### Workflow Schema Object

| Field           | Type    | Description                                   |
| --------------- | ------- | --------------------------------------------- |
| `workflow_id`   | string  | Unique identifier for the workflow            |
| `workflow_name` | string  | Human-readable workflow name                  |
| `version`       | integer | Workflow version number                       |
| `description`   | string  | Description of what the workflow does         |
| `is_active`     | boolean | Whether the workflow is currently active      |
| `variables`     | array   | List of input variables with validation rules |
| `steps`         | array   | List of workflow steps in execution order     |

### Variable Object Fields

| Field           | Type    | Description                                                                                              |
| --------------- | ------- | -------------------------------------------------------------------------------------------------------- |
| `variable_id`   | string  | Unique identifier for the variable                                                                       |
| `variable_name` | string  | Human-readable variable name                                                                             |
| `type`          | string  | Variable type: `text`, `number`, `boolean`, `date`, `email`, `select`, `file`, `user_entity`, `business` |
| `required`      | boolean | Whether the variable is required for workflow initiation                                                 |
| `description`   | string  | Description of what the variable represents                                                              |
| `validation`    | object  | Optional validation rules (e.g., allowed file extensions, value ranges)                                  |

## Error Responses

### 400 Bad Request

Returned when the version format is invalid.

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

### 401 Unauthorized

Returned when authentication fails. See the [authentication errors](/api-reference/introduction#authentication-errors) section for details.

```json theme={null}
{
  "detail": "Invalid API key"
}
```

### 404 Not Found

Returned when the workflow or version doesn't exist.

```json theme={null}
{
  "detail": "Workflow not found"
}
```

### 500 Internal Server Error

Returned when the request fails due to a server error.

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

## Notes

<Info>
  Use `"latest"` as the version to always get the most recent workflow schema without tracking version numbers.
</Info>

<Warning>
  Variable types and validation rules must be respected when initiating workflows. Validation failures will result in a 422 error.
</Warning>

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