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

# Upload Signed Document

> Upload an externally signed document and attach it to a task's signature step, allowing you to complete Flows using signatures collected outside Chamelio.

## Endpoint

```
POST /tasks/{task_id}/upload-signed-document
```

## 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 |
| - | - | - |
| `step_run_id` | string | ID of the signature step run |
| `file` | object | Signed document file to upload. See [File Object](#file-object-fields) |

### File Object Fields

| Field | Type | Description |
| - | - | - |
| `filename` | string | Filename, e.g. `signed_contract.pdf` |
| `base64_content` | string | Base64-encoded file content |

## Request Example

```bash cURL theme={null}
curl -X POST "https://platform.chamelio.ai/tasks/12345/upload-signed-document" \
  -H "X-API-Key: ca_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "step_run_id": "sr_abc123",
    "file": {
      "filename": "signed_contract.pdf",
      "base64_content": "JVBERi0xLjcKJ..."
    }
  }'
```

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

task_id = 12345

with open("signed_contract.pdf", "rb") as f:
    content = base64.b64encode(f.read()).decode("utf-8")

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

payload = {
    "step_run_id": "sr_abc123",
    "file": {
        "filename": "signed_contract.pdf",
        "base64_content": content
    }
}

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}/upload-signed-document`,
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'ca_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      step_run_id: 'sr_abc123',
      file: {
        filename: 'signed_contract.pdf',
        base64_content: 'JVBERi0xLjcKJ...'
      }
    })
  }
);

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

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "task_id": 12345,
  "success": true,
  "output_variable_id": "signed_document"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `task_id` | integer | ID of the task |
| `success` | boolean | Whether the upload succeeded |
| `output_variable_id` | string | Output variable ID for the signed document |

## 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 a signature step or the document cannot be attached in the current state.

```json theme={null}
{
  "detail": "Task is not at a signature step"
}
```

### 422 Validation Error

Returned when the request body is invalid.

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

### 500 Internal Server Error

Returned when the upload fails due to a server error.

```json theme={null}
{
  "detail": "Failed to upload signed document"
}
```

## Notes

> [!NOTE]
>
> Use this endpoint when a document is signed outside Chamelio (for example, a manually signed PDF) and you need to attach the executed copy to the signature step.

> [!TIP]
>
> Call [Get Signature Details](https://docs.chamelio.ai/api-reference/endpoint/tasks/signature-details.md) to obtain the `step_run_id` for the signature step before uploading.

## Use Cases

This endpoint is useful for:

* **Manual signing flows** - Attach wet-signed or externally signed documents to a task
* **Third-party signature providers** - Record the executed document from a provider not integrated with Chamelio
* **Audit completeness** - Ensure the final signed copy is stored against the workflow step
