# POST /api/v2/sprints/{sprint}/actions/complete

Complete a sprint

- MCP id: sprints.actions.complete
- Scope: api:write:project_management
- Permission: project_management::manage_sprints
- Rate cost: 1 unit, write bucket. A write costs the same whatever `view` you ask for.
- Cache-Control: private, no-store

Closes a sprint: clears `is_active` and stamps `completed_at` with the current time, then disposes of the sprint's unresolved work items (those whose workflow status is not a resolution) according to `unresolved_work_items`.

Resolved items always stay on the completed sprint, whichever strategy is chosen, so the closed sprint keeps its delivery history. `move_to_next_sprint` additionally requires `next_sprint_id`, which must name a not-yet-completed sprint on the same project other than this one; anything else is `422` `unprocessable-relationship` pointing at `/next_sprint_id`. A sprint that is already completed refuses with `409` `state-conflict` and `conflict.reason` `already_completed`, and one that was never started refuses the same way with `not_started`. Each moved item is saved on its own, so its audit trail records the move and its `version` is bumped (a client holding their ETags must re-read them), but no per-item notification is sent. Returns the sprint in the detail view; `work_items_count` reflects what is left on it.

## Parameters
- sprint (integer, path): The Sprint's numeric id.
- view (string, optional): Which field set to render.
- X-Request-Id (header, optional): A correlation id of your own. It is recorded in our logs next to the server's request id but never returned: the response header always carries the server's id. A value that does not match the pattern is discarded silently, never rejected.
- If-Match (header, optional): The ETag a write is conditional on. A stale validator is 412 precondition-failed.
- Idempotency-Key (header, optional): A caller-chosen key that makes this POST safe to retry. Replaying it returns the original response with Idempotency-Replayed: true.

## Request body
- unresolved_work_items (string, required): What happens to the sprint's unresolved work items.
- next_sprint_id (integer or null → Sprint.id, optional): Sprint that receives the unresolved work items. Required, and only used, with `move_to_next_sprint`; it must be a not-yet-completed sprint on the same project. Required when unresolved_work_items, move_to_next_sprint.

Unknown keys are refused with `422` validation-failed, naming the key.

## Response 200
- id (integer, required): Unique identifier.
- project_id (integer, required): The project this sprint belongs to. A sprint cannot be moved between projects, so this is accepted on create only.
- name (string ≤ 255, required): Sprint name as shown in plnnrly, e.g. `Sprint 14`.
- description (string or null, required, multiline): Free-text sprint goal. Plain text, not markup.
- start_date (date (YYYY-MM-DD) or null, required): Planned first day of the sprint. Independent of `started_at`: planning a date does not start the sprint.
- end_date (date (YYYY-MM-DD) or null, required): Planned last day of the sprint. Independent of `completed_at`.
- started_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required, server-assigned): When the sprint was actually started. Written only by POST `sprints/{sprint}/actions/start`; `null` on an upcoming sprint.
- completed_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required, server-assigned): When the sprint was actually completed. Written only by POST `sprints/{sprint}/actions/complete`; `null` until then. Non-`null` is what makes the derived state `completed`.
- is_active (boolean, required, server-assigned): Whether this is the project's running sprint. Set by actions/start and cleared by actions/complete, never by PATCH. At most one sprint per project is active at a time.
- order (integer, required, server-assigned): Display position within the project. Assigned on create as the last position in that project's sprint order, changed only by reordering in plnnrly, and not writable.
- work_items_count (integer ≥ 0, required): Number of work items currently on this sprint, resolved and unresolved alike.
- created_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Creation timestamp.
- updated_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Last-write timestamp; use for incremental sync.
- project (Ref or ProjectSummary, required): The project this sprint belongs to. Expanding it additionally requires the projects prefix's read grant and a token scope covering it.
- links (SprintLinks, required)
  - self (url, required): The canonical URI of this record.
  - work_items (url, required): Work items on this sprint.

## Errors
- 403 forbidden-by-policy | insufficient-permission | insufficient-token-scope: Forbidden.
- 409 idempotency-key-in-flight | idempotency-key-reused | state-conflict: Conflict.
- 412 precondition-failed: Precondition failed.
- 415 unsupported-media-type: Unsupported media type.
- 422 unprocessable-relationship | validation-failed: Unprocessable content.
- 400 idempotency-key-required | invalid-cursor | invalid-query-parameter | malformed-request | unsupported-parameter: Bad request.
- 401 token-expired | unauthenticated: Unauthenticated.
- 404 endpoint-not-found | resource-not-found: Not found.
- 406 not-acceptable: Not acceptable.
- 429 rate-limit-exceeded: Too many requests.
- 500 internal-error: Server error.
- 503 tenant-unavailable: Service unavailable.

## Example
```bash
curl -X POST \
  'https://<your-url>/api/v2/sprints/1/actions/complete' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <key>' \
  -d '{
    "unresolved_work_items": "move_to_next_sprint",
    "next_sprint_id": 1
  }'
```
