> ## 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 challenge template

> Create a new challenge template.

<Badge color="green">POST</Badge> `/api/challenge-templates`

Requires authentication.

<ParamField header="Authorization" type="string" required>
  Bearer token obtained from `/api/auth/login` or `/api/auth/signup`. Format: `Bearer <token>`.
</ParamField>

<Warning>
  The API enforces a maximum of **10 challenge templates** at a time. Creating a new template when
  10 already exist returns a `400` error. Delete an existing template first to free up a slot.
</Warning>

## Request body

<ParamField body="title" type="string" required>
  Display name of the challenge. Must not be empty.
</ParamField>

<ParamField body="description" type="string" required>
  Full description of the challenge goal and instructions.
</ParamField>

<ParamField body="duration_days" type="number" required>
  Number of consecutive days the challenge runs. Must not be empty.
</ParamField>

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url http://localhost:3000/api/challenge-templates \
    --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
    --header 'Content-Type: application/json' \
    --data '{
      "title": "Desafio de 10 Dias",
      "description": "Dez dias para consolidar um novo hábito e sentir a diferença na sua rotina.",
      "duration_days": 10
    }'
  ```
</CodeGroup>

## Response

**201 Created**

Returns the newly created challenge template object.

<ResponseField name="id" type="number" required>
  Unique numeric identifier assigned to the new template.
</ResponseField>

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

<ResponseField name="description" type="string" required>
  Full description of the challenge goal and instructions.
</ResponseField>

<ResponseField name="duration_days" type="number" required>
  Number of consecutive days the challenge runs.
</ResponseField>

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

<ResponseField name="updated_at" type="string" required>
  ISO 8601 timestamp of the last update to the template.
</ResponseField>

```json Example response theme={null}
{
  "id": 8,
  "title": "Desafio de 10 Dias",
  "description": "Dez dias para consolidar um novo hábito e sentir a diferença na sua rotina.",
  "duration_days": 10,
  "created_at": "2026-03-17T12:00:00.000Z",
  "updated_at": "2026-03-17T12:00:00.000Z"
}
```

## Errors

| Status | Description                                                                       |
| ------ | --------------------------------------------------------------------------------- |
| `400`  | `title` or `duration_days` is missing, or the 10-template limit has been reached. |
| `401`  | Missing, invalid, or expired token.                                               |
