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

# Create Task

> Create a new task linked to a project

# Create Task

Create a new task linked to a project. The assigned user receives an email notification unless they are the creator.

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

<ParamField header="Accept-Language" type="string" default="es">
  Language for the notification email: `en`, `es`, `fr`, `pt`, `it`, `de`
</ParamField>

### Body Parameters

<ParamField body="project_id" type="string" required>
  UUID of the project to link the task to
</ParamField>

<ParamField body="title" type="string" required>
  Task title
</ParamField>

<ParamField body="assigned_to" type="string" required>
  UUID of the user to assign the task to
</ParamField>

<ParamField body="description" type="string">
  Task description
</ParamField>

<ParamField body="due_date" type="string">
  Due date (YYYY-MM-DD)
</ParamField>

<ParamField body="stage" type="string">
  Initial stage: `not_applicable`, `pending`, `in_progress`, `completed`, `validated`
</ParamField>

<ParamField body="category" type="string">
  Task category
</ParamField>

<ParamField body="parent_task_id" type="string">
  UUID of the parent task (creates a subtask)
</ParamField>

<ParamField body="progress" type="number">
  Initial progress (0–100)
</ParamField>

<ParamField body="tags" type="string[]">
  List of tags
</ParamField>

<ParamField body="comments" type="string[]">
  Initial comments to add to the task
</ParamField>

## Response (201 Created)

<ResponseField name="id" type="string">
  Created task UUID
</ResponseField>

<ResponseField name="title" type="string">
  Task title
</ResponseField>

<ResponseField name="stage" type="string">
  Task stage
</ResponseField>

<ResponseField name="assigned_to" type="object">
  Assigned user details
</ResponseField>

<ResponseField name="projects" type="array[object]">
  Linked projects
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v2/tasks" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "project_id": "project-uuid",
      "title": "Upload Q2 electricity invoices",
      "assigned_to": "user-uuid",
      "description": "Upload all Q2 2025 electricity invoices for Madrid office",
      "due_date": "2025-07-15",
      "stage": "pending",
      "tags": ["invoices", "Q2"]
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  response = requests.post(
      "https://api.dcycle.io/v2/tasks",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "Content-Type": "application/json",
      },
      json={
          "project_id": "project-uuid",
          "title": "Upload Q2 electricity invoices",
          "assigned_to": "user-uuid",
          "description": "Upload all Q2 2025 electricity invoices for Madrid office",
          "due_date": "2025-07-15",
          "stage": "pending",
          "tags": ["invoices", "Q2"],
      },
  )

  task = response.json()
  print(f"Created task: {task['id']} — {task['title']}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const { data: task } = await axios.post(
    'https://api.dcycle.io/v2/tasks',
    {
      project_id: 'project-uuid',
      title: 'Upload Q2 electricity invoices',
      assigned_to: 'user-uuid',
      description: 'Upload all Q2 2025 electricity invoices for Madrid office',
      due_date: '2025-07-15',
      stage: 'pending',
      tags: ['invoices', 'Q2'],
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'Content-Type': 'application/json',
      },
    }
  );

  console.log(`Created task: ${task.id} — ${task.title}`);
  ```
</CodeGroup>

### Successful Response (201)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "task-uuid",
  "title": "Upload Q2 electricity invoices",
  "description": "Upload all Q2 2025 electricity invoices for Madrid office",
  "due_date": "2025-07-15",
  "stage": "pending",
  "category": null,
  "organization_id": "org-uuid",
  "assigned_to": {
    "id": "user-uuid",
    "first_name": "Carlos",
    "last_name": "López",
    "email": "carlos@example.com"
  },
  "projects": [
    { "id": "project-uuid", "name": "Carbon Footprint 2025" }
  ],
  "comments": [],
  "progress": null,
  "tags": ["invoices", "Q2"]
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 422 Unprocessable Entity

**Cause:** Invalid or missing required fields in the request body

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "title"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Task" icon="eye" href="/api-reference/projects/get-task">
    Retrieve task details
  </Card>

  <Card title="Update Task" icon="pen" href="/api-reference/projects/update-task">
    Modify task fields
  </Card>
</CardGroup>
