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

# Approve Task

> Submit an approval or rejection decision for a workflow task currently at an approval step, optionally including comments and populated variable values.

## Endpoint

```
POST /tasks/{task_id}/approve
```

## 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 |
| - | - | - | - |
| `task_id` | integer | Yes | Unique identifier for the task |

## Request Body

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

### Required Fields

| Field | Type | Description |
| - | - | - |
| `approved` | boolean | Whether the task is approved (`true`) or rejected (`false`) |

### Optional Fields

| Field | Type | Description |
| - | - | - |
| `comment` | string | Optional comment explaining the approval or rejection decision |
| `variables` | array | Additional variable values collected during the approval step. Accepts the same InputValue types as [Initiate Workflow](https://docs.chamelio.ai/api-reference/endpoint/workflows/initiate.md#inputvalue-types), including `file` and `multiple_files` |
| `user_email` | string | Email of the user submitting the approval (defaults to API key owner) |

## Request Example

```bash cURL theme={null}
curl -X POST "https://platform.chamelio.ai/tasks/12345/approve" \
  -H "X-API-Key: ca_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "approved": true,
    "comment": "Contract terms look acceptable. Approved for signing.",
    "variables": [
      {
        "variable_id": "approval_notes",
        "type": "text",
        "value": "Verify insurance requirements before final signature"
      }
    ],
    "user_email": "manager@example.com"
  }'
```

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

task_id = 12345

url = f"https://platform.chamelio.ai/tasks/{task_id}/approve"
headers = {
    "X-API-Key": "ca_your_api_key_here",
    "Content-Type": "application/json"
}

payload = {
    "approved": True,
    "comment": "Contract terms look acceptable. Approved for signing.",
    "variables": [
        {
            "variable_id": "approval_notes",
            "type": "text",
            "value": "Verify insurance requirements before final signature"
        }
    ],
    "user_email": "manager@example.com"
}

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

```javascript JavaScript theme={null}
const taskId = 12345;

const response = await fetch(
  `https://platform.chamelio.ai/tasks/${taskId}/approve`,
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'ca_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      approved: true,
      comment: 'Contract terms look acceptable. Approved for signing.',
      variables: [
        {
          variable_id: 'approval_notes',
          type: 'text',
          value: 'Verify insurance requirements before final signature'
        }
      ],
      user_email: 'manager@example.com'
    })
  }
);

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

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "task_id": 12345,
  "status": "in_progress",
  "approved": true,
  "message": "Approval submitted successfully"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `task_id` | integer | ID of the task |
| `status` | string | Updated task status (typically `"in_progress"` as workflow continues to next step) |
| `approved` | boolean | Whether the task was approved or rejected |
| `message` | string | Success confirmation message |

## Error Responses

### 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 task doesn't exist or you don't have access to it.

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

### 409 Conflict

Returned when the task is not at an approval step or has already been approved/rejected.

```json theme={null}
{
  "detail": "Task is not awaiting approval"
}
```

### 422 Validation Error

Returned when the request body is invalid or variables don't match the expected schema.

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

### 500 Internal Server Error

Returned when submission fails due to a server error.

```json theme={null}
{
  "detail": "Failed to submit approval"
}
```

## Notes

> [!NOTE]
>
> When a task is approved, the workflow continues to the next step. When rejected, the workflow typically ends or follows a rejection path defined in the workflow.

> [!TIP]
>
> Use the `comment` field to document the reasoning behind approval or rejection decisions for audit and compliance purposes.

> [!WARNING]
>
> Ensure the task is at an approval step before calling this endpoint. Check the `current_step_type` from the [Get Task](https://docs.chamelio.ai/api-reference/endpoint/tasks/get.md) endpoint.

## Use Cases

This endpoint is useful for:

* **Automated approvals** - Integrate approval workflows with external systems
* **Custom approval UIs** - Build custom interfaces for task approval
* **Conditional approvals** - Approve tasks based on external business logic
* **Bulk approvals** - Process multiple approval requests programmatically
