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

# Complete challenge

> Mark a user challenge as completed.

<Badge color="orange">PUT</Badge> `/api/user-challenges/:id/complete`

Requires authentication.

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

<Note>
  Completing a challenge sets its `status` to `COMPLETED` and records the current timestamp in
  `completed_at`. Once completed, the user is free to accept a new challenge.
</Note>

## Path parameters

<ParamField path="id" type="number" required>
  The numeric ID of the user challenge to complete.
</ParamField>

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl --request PUT \
    --url http://localhost:3000/api/user-challenges/14/complete \
    --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
  ```
</CodeGroup>

## Response

**200 OK**

Returns the updated user challenge object with `status` set to `COMPLETED` and `completed_at`
set to the current timestamp.

<ResponseField name="id" type="number" required>
  Unique numeric identifier for this user challenge.
</ResponseField>

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

<ResponseField name="template_id" type="number" required>
  ID of the challenge template this challenge is based on.
</ResponseField>

<ResponseField name="status" type="string" required>
  Updated status. Always `COMPLETED` after this operation.
</ResponseField>

<ResponseField name="start_date" type="string" required>
  ISO 8601 timestamp of when the challenge was started.
</ResponseField>

<ResponseField name="completed_at" type="string" required>
  ISO 8601 timestamp of when the challenge was marked as completed.
</ResponseField>

<ResponseField name="notes" type="string">
  Progress notes for the challenge. `null` if none were added.
</ResponseField>

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

<ResponseField name="updated_at" type="string" required>
  ISO 8601 timestamp of this update.
</ResponseField>

```json Example response theme={null}
{
  "id": 14,
  "user_id": "a3f2c1d0-89b4-4e7a-b6f5-1234567890ab",
  "template_id": 3,
  "status": "COMPLETED",
  "start_date": "2026-03-17T09:00:00.000Z",
  "completed_at": "2026-03-17T21:45:00.000Z",
  "notes": "Consegui manter o hábito todos os dias!",
  "created_at": "2026-03-17T09:00:00.000Z",
  "updated_at": "2026-03-17T21:45:00.000Z"
}
```

## Errors

| Status | Description                                  |
| ------ | -------------------------------------------- |
| `401`  | Missing, invalid, or expired token.          |
| `404`  | No user challenge found with the given `id`. |
