> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/RafaeltiMoreira/mais-habito-api/llms.txt
> Use this file to discover all available pages before exploring further.

# Create task

> Create a new task for the authenticated user.

<Note>
  Set `is_daily_routine` to `true` for tasks that repeat every day as part of your regular habits (e.g., "Drink 2L of water"). Leave it `false` for one-off tasks (e.g., "Read a book this week"). The flag does not enforce any scheduling logic — it is a label that helps you and the app distinguish recurring habits from standalone goals.
</Note>

## Request body

<ParamField body="title" type="string" required>
  Display name for the task. Cannot be empty.
</ParamField>

<ParamField body="points" type="number" required default="10">
  Points awarded to the user each time this task is completed. Must be greater than zero. Defaults to `10` when not provided.
</ParamField>

<ParamField body="description" type="string">
  Optional longer description of the task.
</ParamField>

<ParamField body="is_daily_routine" type="boolean" default="false">
  Whether this task is part of the user's daily routine. Defaults to `false`.
</ParamField>

<ParamField body="challenge_template_id" type="number">
  Associate this task with a challenge template. When provided, the user must currently have an active challenge that matches this template ID, otherwise the request returns `400`.
</ParamField>

## Response

**201 Created** — Returns the newly created task object.

<ResponseField name="id" type="number" required>
  Auto-incremented unique identifier for the task.
</ResponseField>

<ResponseField name="user_id" type="string" required>
  UUID of the user who owns the task.
</ResponseField>

<ResponseField name="challenge_template_id" type="number | null" required>
  ID of the associated challenge template, or `null` if not linked to a challenge.
</ResponseField>

<ResponseField name="title" type="string" required>
  Display name of the task.
</ResponseField>

<ResponseField name="description" type="string | null" required>
  Optional description, or `null` if not provided.
</ResponseField>

<ResponseField name="points" type="number" required>
  Points awarded per completion.
</ResponseField>

<ResponseField name="is_daily_routine" type="boolean" required>
  Whether the task is flagged as a daily routine.
</ResponseField>

<ResponseField name="created_at" type="string" required>
  ISO 8601 timestamp of when the task was created.
</ResponseField>

<ResponseField name="updated_at" type="string" required>
  ISO 8601 timestamp of when the task was last updated.
</ResponseField>

## Errors

| Status | Condition                                                                                                  |
| ------ | ---------------------------------------------------------------------------------------------------------- |
| `400`  | `points` is zero or negative.                                                                              |
| `400`  | `challenge_template_id` is provided but the user does not have an active challenge matching that template. |
| `404`  | `challenge_template_id` is provided but the template does not exist.                                       |
| `401`  | Missing or invalid authentication token.                                                                   |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url http://localhost:3000/api/tasks \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "title": "Meditate for 10 minutes",
      "description": "Morning meditation session",
      "points": 20,
      "is_daily_routine": true
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": 42,
    "user_id": "a3f1c2d4-0e5b-4a7f-b891-2c3d4e5f6a7b",
    "challenge_template_id": null,
    "title": "Meditate for 10 minutes",
    "description": "Morning meditation session",
    "points": 20,
    "is_daily_routine": true,
    "created_at": "2026-03-17T08:00:00.000Z",
    "updated_at": "2026-03-17T08:00:00.000Z"
  }
  ```

  ```json 400 theme={null}
  {
    "error": "Points must be greater than zero"
  }
  ```

  ```json 401 theme={null}
  {
    "error": "User not authenticated"
  }
  ```
</ResponseExample>
