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

# Initiate Workflow (Flexible)

> Start a new workflow task with flexible key-value variable pairs and automatic type detection, useful when integrating from systems without strict schemas.

## Endpoint

```
POST /workflows/{workflow_id}/{version}/initiate-simple
```

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

The request body must be a JSON object with the following fields:

### Required Fields

| Field | Type | Description |
| - | - | - |
| `attributes` | array | List of simple key-value pairs for workflow variables (see below) |

### Optional Fields

| Field | Type | Description |
| - | - | - |
| `files` | array | List of files with base64 content (see File Format below) |
| `extra_attachments` | array | Additional files attached to the task but not mapped to any workflow variable. Same object shape as `files` |
| `user` | string | Email address of the user initiating the workflow. If not provided, workflow is attributed to the API key owner |
| `metadata` | object | Key-value pairs (strings) to attach to the task |
| `auto_creation_of_extra_variables` | boolean | When `true`, attributes that matched no workflow field, plus `metadata` entries, are passed as extra variables so the workflow can auto-create them. Defaults to `false`, in which case unmatched attributes are dropped |

### Attribute Format

Each attribute is a simple object with `key` and `value` fields:

```json theme={null}
{
  "key": "vendor_name",
  "value": "Acme Corporation"
}
```

The system will match attributes to workflow variables using flexible matching:

1. Exact match by variable ID
2. Case-insensitive match by variable title
3. Normalized match (lowercase, spaces/underscores/hyphens ignored)

> [!NOTE]
>
> Values are provided as strings. The system will automatically convert them to the appropriate type based on the workflow schema. Amounts with an explicit currency and table fields work differently, as described below.

#### Amounts with a currency

For a `number_with_currency` field, a plain string such as `"50000.00"` uses the field's default currency. To set the currency, send `value` as an object with `value` and `currency`:

```json theme={null}
{
  "key": "contract_value",
  "value": {
    "value": "50000.00",
    "currency": "EUR"
  }
}
```

The currency must be a [supported ISO 4217 code](https://docs.chamelio.ai/api-reference/endpoint/workflows/initiate.md#number-with-currency-inputvalue) and, if the field restricts its currencies, one of the field's `currencies`. An attribute with a currency must match a `number_with_currency` field. If it matches no field, or matches a field of another type, the request returns a `400` instead of skipping the attribute.

#### Table fields

For a `dynamic_table` field, send `value` as a string containing a JSON array of rows. Each row is an object keyed by column name, or a list of cells in column order, as described in [Dynamic Table InputValue](https://docs.chamelio.ai/api-reference/endpoint/workflows/initiate.md#dynamic-table-inputvalue):

```json theme={null}
{
  "key": "Line Items",
  "value": "[{\"Item\": \"Laptop\", \"Quantity\": 2}, {\"Item\": \"Monitor\", \"Quantity\": 3}]"
}
```

A value that isn't a JSON array of objects or lists returns a `400`.

### File Format

Files are provided separately from attributes:

```json theme={null}
{
  "filename": "contract.pdf",
  "base64_content": "JVBERi0xLjQKJeLjz9MK..."
}
```

> [!WARNING]
>
> Files are matched to workflow fields by order. Single file fields are filled first, in order. Any leftover files spill into the workflow's `multiple_files` variable if one exists; otherwise they are attached to the task as extra attachments. Ensure files in the array correspond to the order of file fields in your workflow.

> [!NOTE]
>
> Files are validated against the platform's supported file extensions. Files with unsupported extensions are skipped rather than coerced.

## When to Use This Endpoint

This endpoint is designed for scenarios where the integrating system or user **cannot maintain variable-specific mapping and control**. Use this endpoint when:

* **Generic integration systems** that handle multiple workflows without custom configuration for each
* **Low-code/no-code platforms** where users configure integrations through UI without coding
* **Form builders** that generate dynamic field mappings based on workflow schemas
* **Third-party tools** that need to integrate with workflows but can't be customized for each workflow's schema
* **Rapid prototyping** where you want to test workflows without setting up precise type mappings
* **Simple scripts** where maintaining detailed variable schemas adds unnecessary complexity

The flexible matching (by ID, title, or normalized name) means integrating systems can use human-readable labels without knowing the exact internal variable IDs.

> [!NOTE]
>
> If your integration requires precise control over variable types, file references, or needs to distinguish between fields with similar names, use the standard [Initiate Workflow](https://docs.chamelio.ai/api-reference/endpoint/workflows/initiate.md) endpoint instead.

## Request Example

```bash cURL theme={null}
curl -X POST "https://platform.chamelio.ai/workflows/vendor_contract_review/latest/initiate-simple" \
  -H "X-API-Key: ca_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "attributes": [
      {
        "key": "vendor_name",
        "value": "Acme Corporation"
      },
      {
        "key": "contract_value",
        "value": "150000.00"
      },
      {
        "key": "reviewer_email",
        "value": "legal@example.com"
      },
      {
        "key": "urgent",
        "value": "true"
      }
    ],
    "files": [
      {
        "filename": "acme_contract.pdf",
        "base64_content": "JVBERi0xLjQKJeLjz9MK..."
      }
    ],
    "user": "john.doe@example.com"
  }'
```

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

workflow_id = "vendor_contract_review"
version = "latest"

# Read and encode file
with open("acme_contract.pdf", "rb") as f:
    file_content = base64.b64encode(f.read()).decode('utf-8')

url = f"https://platform.chamelio.ai/workflows/{workflow_id}/{version}/initiate-simple"
headers = {
    "X-API-Key": "ca_your_api_key_here",
    "Content-Type": "application/json"
}

payload = {
    "attributes": [
        {
            "key": "vendor_name",
            "value": "Acme Corporation"
        },
        {
            "key": "contract_value",
            "value": "150000.00"
        },
        {
            "key": "reviewer_email",
            "value": "legal@example.com"
        }
    ],
    "files": [
        {
            "filename": "acme_contract.pdf",
            "base64_content": file_content
        }
    ],
    "user": "john.doe@example.com"
}

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

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

// Convert file to base64
const fileToBase64 = (file) => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result.split(',')[1]);
    reader.onerror = error => reject(error);
  });
};

// Assuming you have a File object
const base64Content = await fileToBase64(fileObject);

const response = await fetch(
  `https://platform.chamelio.ai/workflows/${workflowId}/${version}/initiate-simple`,
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'ca_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      attributes: [
        {
          key: 'vendor_name',
          value: 'Acme Corporation'
        },
        {
          key: 'contract_value',
          value: '150000.00'
        },
        {
          key: 'reviewer_email',
          value: 'legal@example.com'
        }
      ],
      files: [
        {
          filename: 'acme_contract.pdf',
          base64_content: base64Content
        }
      ],
      user: 'john.doe@example.com'
    })
  }
);

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

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "task_id": 12345,
  "task_url": "https://app.chamelio.ai/b/workflows/tasks/12345",
  "workflow_state_id": "wfs_abc123xyz",
  "workflow_id": "vendor_contract_review",
  "version": 1,
  "status": "in_progress",
  "message": "Workflow initiated successfully"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `task_id` | integer or null | Unique identifier for the created task. Use this to track task status |
| `task_url` | string or null | Link to the created task in the Chamelio app. `null` when no task was created |
| `workflow_state_id` | string | Internal workflow state identifier |
| `workflow_id` | string | Workflow identifier that was initiated |
| `version` | integer | Workflow version number that was used |
| `status` | string | Initial task status (typically `"in_progress"` or `"pending"`) |
| `message` | string | Success confirmation message |

## Error Responses

### 400 Bad Request

Returned when the version format is invalid, request structure is malformed, attribute matching fails, or a currency or table attribute fails the workflow's rules.

```json theme={null}
{
  "detail": "Could not match attribute 'invalid_key' to any workflow variable"
}
```

```json theme={null}
{
  "detail": "Attribute 'contract_value' has a currency but does not match any number_with_currency field"
}
```

```json theme={null}
{
  "detail": "Currency 'EUR' is not allowed for 'contract_value' (allowed: USD, GBP)"
}
```

```json theme={null}
{
  "detail": "Table field 'Line Items' must be a JSON array of rows"
}
```

### 401 Unauthorized

Returned when authentication fails. See the [authentication errors](https://docs.chamelio.ai/api-reference/api-keys.md#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"
}
```

### 422 Validation Error

Returned when the request body is invalid or required variables are missing.

```json theme={null}
{
  "detail": [
    {
      "loc": ["body", "attributes"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

### 500 Internal Server Error

Returned when workflow initiation fails due to a server error.

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

## Comparison with `/initiate`

| Aspect | `/initiate` | `/initiate-simple` |
| - | - | - |
| Input format | Typed `InputValue` objects | Simple `{key, value}` pairs |
| Variable matching | Exact `variable_id` only | Flexible: ID → title → normalized |
| File handling | Requires `file_id` or typed object | Base64 content, matched by order |
| Type specification | Explicit `type` field required | Auto-detected from schema |
| Use case | Precise control, file references | Systems without variable-specific mapping |

## Notes

> [!NOTE]
>
> Save the `task_id` from the response to track the workflow's progress using the [Get Task](https://docs.chamelio.ai/api-reference/endpoint/tasks/get.md) endpoint.

> [!TIP]
>
> Use flexible attribute keys: "Vendor Name", "vendor\_name", and "vendor-name" will all match the same variable.

> [!WARNING]
>
> Files in the `files` array are matched to workflow file fields by position. The first file in the array is assigned to the first file field in the workflow, and so on. Files left over after all single file fields are filled go to the workflow's `multiple_files` variable if it has one, or are attached to the task as extra attachments otherwise.

## Use Cases

This flexible endpoint is ideal for:

* **Generic integration platforms** - Integration platforms (iPaaS) that connect to multiple workflows without per-workflow configuration
* **Form builders** - Dynamic forms that adapt to workflow schemas without hardcoded field mappings
* **No-code tools** - Platforms where users configure integrations visually without access to variable IDs
* **Multi-tenant systems** - Applications serving multiple organizations with different workflow schemas
* **API aggregators** - Services that normalize data from various sources before initiating workflows
* **Rapid prototyping** - Quick testing without setting up precise variable mappings
* **Simple scripts** - Automation where maintaining detailed schemas is unnecessary overhead

**Key advantage**: Integrating systems don't need to maintain a mapping table between their field names and Chamelio's internal variable IDs. They can use human-readable labels directly.

For precise control over variable types, file references, or when you need to distinguish between similarly-named fields, use the standard [Initiate Workflow](https://docs.chamelio.ai/api-reference/endpoint/workflows/initiate.md) endpoint.
