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

# Create Task

> Create a new task linked to a contact, deal, or event

## Request

<Warning>
  **At least one parent link is required.** A task must reference `contact_id`, `deal_id`, or `event_id`. Orphan tasks are rejected with `400`.
</Warning>

### Body Parameters

<ParamField body="title" type="string" required>Task title</ParamField>
<ParamField body="description" type="string">Task description</ParamField>
<ParamField body="status" type="string" default="open">Status (`open`, `in_progress`, `completed`)</ParamField>
<ParamField body="priority" type="string">Priority level (`low`, `medium`, `high`)</ParamField>
<ParamField body="task_type" type="string">Task type</ParamField>
<ParamField body="due_date" type="string">Due date (ISO 8601 or `YYYY-MM-DD`)</ParamField>
<ParamField body="assignee_id" type="string">Assignee user ID</ParamField>
<ParamField body="contact_id" type="string">UUID of linked contact. Must belong to your workspace.</ParamField>

<ParamField body="contact_name" type="string">
  Human name — fuzzy-matched within your workspace and resolved to `contact_id`.
  On ambiguous matches, returns `400 ambiguous_reference` with candidate UUIDs.
</ParamField>

<ParamField body="company_name" type="string">Human name — fuzzy Company match.</ParamField>
<ParamField body="deal_id" type="string">UUID of linked deal.</ParamField>
<ParamField body="event_id" type="string">UUID of linked event.</ParamField>

<ParamField body="created_date" type="string">
  Optional ISO 8601 timestamp. Honored verbatim if within the last 5 years and not more than 24 h in the future; otherwise the server `now()` is used. Never null.
</ParamField>

### Headers

```
Authorization: Bearer wbk_your_api_key_here
Content-Type: application/json
```

## Response

<ResponseField name="data" type="object">
  Created task with `id`, `title`, `status`, `priority`, `due_date`, `assigned_to_user_id`, `contact_id`, `deal_id`, `event_id`, `created_date`.
</ResponseField>

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://data.leadlex.com/functions/v1/api-gateway/v1/tasks \
    -H "Authorization: Bearer wbk_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "title": "Follow up with Hans Müller",
      "due_date": "2026-03-10",
      "priority": "high",
      "contact_id": "789e0123-e45b-67c8-a901-234567890abc"
    }'
  ```

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

  API_KEY = "wbk_your_api_key_here"
  BASE_URL = "https://data.leadlex.com/functions/v1/api-gateway"

  headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
  response = requests.post(f"{BASE_URL}/v1/tasks", headers=headers, json={
      "title": "Follow up with Hans Müller",
      "due_date": "2026-03-10",
      "priority": "high",
      "contact_id": "789e0123-e45b-67c8-a901-234567890abc",
  })
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://data.leadlex.com/functions/v1/api-gateway/v1/tasks',
    {
      method: 'POST',
      headers: { 'Authorization': 'Bearer wbk_your_api_key_here', 'Content-Type': 'application/json' },
      body: JSON.stringify({
        title: 'Follow up with Hans Müller',
        due_date: '2026-03-10',
        priority: 'high',
        contact_id: '789e0123-e45b-67c8-a901-234567890abc'
      })
    }
  );
  const { data } = await response.json();
  ```
</CodeGroup>

## Errors

| Status | Code                       | Description                                                                 |
| ------ | -------------------------- | --------------------------------------------------------------------------- |
| 400    | `validation_error`         | Missing `title` — or no parent link (`contact_id` / `deal_id` / `event_id`) |
| 403    | `insufficient_permissions` | Missing `activities:write` permission                                       |

### Orphan-task rejection example

```json theme={null}
{
  "error": {
    "code": "validation_error",
    "message": "At least one parent link (contact_id, company_id, deal_id, or event_id) is required"
  }
}
```
