# Inspections and verdicts

> An integration creates inspection templates, checklists and inspection plans, opens inspections, records verdicts and checks, reopens steps and hands off zones.

An integration, such as a quality system or a contractor's site planning tool, can set up a project's inspections as a project administrator does in the app: templates with their steps, checklists, inspection plans with their scope and assignees, inspections created in advance and QR labels for a plan's elements. It can also open an element's inspection as a scan does, comment on and photograph a step, record verdicts and checks, reopen a step and hand off a zone. What it records shows as *Integration · {name}*.

## What you need

- The permission `inspections:write` to create and change, and `inspections:delete` to delete templates, checklists and plans, create a plan's inspections in advance (they then stay open for good), remove inspections created in advance and take elements out of a plan. Either gives the integration the administrator role on its projects, because these are administrator actions in the app. In another organisation's project its role is the one that project's administrator chose, so the administrator actions answer `403 INSUFFICIENT_PROJECT_ROLE` there; see [Integrations in another organisation's project](/en/integrations/other-organisations-projects/).
- `elements:write` as well for `POST …/labels`, the QR labels of a plan's scope. `assign` creates the labels of the elements it adds without it, as in the app.
- `inspections:attest` (*Records verdicts* in the permission picker) to record verdicts and checks, reopen steps and hand off zones. It gives the integration the inspector role on its projects. It records in inspections without a plan and in plans of its own organisation; in another organisation's plan the answer is `403 PLAN_RECORDED_BY_OWNER`.
- `findings:write` (*Records and edits findings and publishes finding drafts*) as well to attach a photo to a step: the photo is uploaded first with [`uploadFindingPhoto`](/en/api-reference/operations/uploadfindingphoto/) (`POST /v1/projects/{projectId}/photos`), which needs it.
- An [access token](/en/integrations/get-an-access-token/) whose scopes include them. Reading needs only `inspections:read`.

## Templates and checklists

A template holds an inspection's steps in order. A step is passed with one verdict, or through the checks of the checklist it names:

```sh
curl -X POST "https://api.whatsbuilt.fi/v1/projects/$PROJECT/templates" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: columns-template-1" \
  -d '{"name":"Column installation","steps":[{"name":"Installation"},{"name":"Grouting","check_list_id":"'$CHECKLIST'"}]}'
```

Create the checklist first with `POST /v1/projects/{projectId}/check-lists` and its checks in `items`. Changing `items` makes a new version of the checklist; a result already recorded stays with the version it was recorded against. `GET /v1/projects/{projectId}/check-lists/{checkListId}` returns the current version and the versions newest first, 20 at a time (`versions_limit` up to 100, and about 2 MB at most); pass `next_before` as `versions_before` until it is null.

`PATCH /v1/projects/{projectId}/templates/{templateId}` with `steps` replaces the list: a step with its `id` stays, one without is new and one left out is removed. A step with recorded results cannot be removed (`409 STEP_HAS_RESULTS`). `"is_default": true` makes the template the project's default template, which opens for an element no plan covers.

A template or checklist that inspections or plans use cannot be deleted (`409 TEMPLATE_IN_USE`, `409 CHECK_GROUP_IN_USE`). Templates and checklists of the organisation are read with the same addresses but changed only in the app.

`GET /v1/projects/{projectId}/fail-reason-lists` returns the organisation's lists of failure reasons that a step can name in `fail_reason_list_id`.

## Inspection plans

A plan binds a template to the elements in its scope, with assignees and a due date. The scope filters by IFC type and storey; `{}` is the whole project:

```sh
curl -X POST "https://api.whatsbuilt.fi/v1/projects/$PROJECT/inspection-plans" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: columns-plan-1" \
  -d '{"template_id":"'$TEMPLATE'","name":"Columns, floor 1","scope":{"ifc_type":["IfcColumn"],"storey_name":["1. krs"]},"due_date":"2026-12-18","assignee_ids":["'$USER'"]}'
```

A plan starts as a draft, which only administrators see. An archived plan stays readable for every role, with `status: archived`, as its inspections stay in the app. Activate it with `PATCH … {"status":"active"}`. `POST /v1/projects/{projectId}/inspection-plans/preview` tells what a scope covers before you save it, and `GET …/inspection-plans/{planId}` how far the scope is inspected.

`POST /v1/projects/{projectId}/inspection-plans/assign` adds elements outside the filter to the active plan of a template, by `global_ids` (up to 500) or by `filter`; each gets its inspection and a QR label. One call handles up to 500 elements, fewer for a template of more than 12 steps. A list of more `global_ids` than that answers `400 VALIDATION_ERROR` and nothing is written; `details[0].maximum` is the most ids one call takes under the template. With `"partial": true` such a call handles the first ids of the list instead: `taken` says how many it handled and `remaining` how many are left, so send the `global_ids` after the first `taken` next. A `filter` call answers `taken` and `remaining` too: send the same `filter` until `remaining` is 0. `"dry_run": true` only counts them. `DELETE …/inspection-plans/{planId}/elements` removes the added elements again, and `DELETE …/elements/{globalId}` puts an excluded element back.

`GET …/inspection-plans/{planId}/scope` lists the elements in scope by state: `not_scanned`, `in_progress`, `done` and `failed`.

## Inspections in advance and labels

`POST …/inspection-plans/{planId}/precreate` (with `inspections:delete`) creates the missing inspections of the plan's scope, up to 1,000 at a time, fewer for a template of more than 5 steps (the plan's `precreation.per_call`); call again until `remaining` is 0. `DELETE …/precreated` removes those not touched yet. `POST …/labels` creates QR labels for elements in scope that have none, 500 at a time.

## Open an inspection

```sh
curl -X POST "https://api.whatsbuilt.fi/v1/projects/$PROJECT/inspections" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"global_id":"2qL7xVb0P1hO3kQm9aZ002"}'
```

This returns the element's inspection, as a scan does, and creates it with its number, such as `INSP-00042`, when the element has none. When several active plans cover the element, the answer is `409 PLAN_CHOICE_REQUIRED` with the plans in `details.plans`; send one of them as `plan_id`.

`POST …/inspections/{inspectionId}/steps/{stepId}/comments` comments on a step, and `…/viewpoints` attaches a photo uploaded with [`uploadFindingPhoto`](/en/api-reference/operations/uploadfindingphoto/). The integration is the author.

In every step address, `{stepId}` is the step's `step_id` in the `steps` of [`getInspection`](/en/api-reference/operations/getinspection/) or `listInspections`, the template step's id. It is not the step's `id`, which names the step's result row: sending that answers `400 NO_LINKED_TOPIC` to a comment or photo.

## Record verdicts and checks

```sh
curl -X POST "https://api.whatsbuilt.fi/v1/projects/$PROJECT/inspections/$INSPECTION/steps/$STEP/verdict" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: insp-42-installation" \
  -d '{"status":"failed","fail_reason":"Misaligned","notes":"Column leans 15 mm"}'
```

`status` is `ok`, `failed` or `na` (does not apply, with its reason in `notes`). Recording again replaces the verdict, as in the app, and a repeat with the same `Idempotency-Key` and body records nothing new. Send `occurred_at` when the verdict happened earlier than now; the answer then marks it entered later. Each call returns the inspection as `getInspection` does.

A sequential step waits for the required steps before it: until they pass, its verdict answers `409 PRIOR_STEP_INCOMPLETE`. A failed verdict does not wait.

A step with a checklist is passed by its checks, and a verdict on it answers `409 STEP_HAS_CHECKS`. Record each check with `POST …/steps/{stepId}/checks/{itemId}` and the same body with `note` in place of `notes`. `{itemId}` is the check's `id` in the checklist version the step is pinned to: the step's `check_list_version_id` is that version, and [`getCheckList`](/en/api-reference/operations/getchecklist/) returns its items. When every required check is ok or does not apply, the step passes; a failed check fails it.

`POST …/steps/{stepId}/reopen` with an optional `reason` takes a verdict back: the step returns to pending and the earlier verdict stays in its history. Only who recorded the verdict, or a project administrator, may reopen it (`403 STEP_REOPEN_NOT_ALLOWED`). A pending step answers `200` unchanged.

## Hand off a zone

On a project whose organisation uses the takt board, `POST /v1/projects/{projectId}/handoffs` marks a zone's work `done`, `received`, `returned`, `approved` or `reopened`, as the handoff in the app does:

```sh
curl -X POST "https://api.whatsbuilt.fi/v1/projects/$PROJECT/handoffs" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: krs01-installation-done" \
  -d '{"zone_id":"'$ZONE'","work_name":"Elementtiasennus","kind":"done"}'
```

`work_name` hands off every task of that work in the zone, and `task_id` one task. `defects` become findings on their elements; a receive with a blocking defect is stored as `returned`. A kind that does not follow the task's state answers `409 HANDOFF_TRANSITION_INVALID`. The answer lists the events recorded, and a repeat with the same key and body returns them with `replayed: true`.

`done` needs the inspector role, which `inspections:attest` gives. `received`, `returned`, `approved` and `reopened` need the project admin role, which a scope such as `inspections:write` gives; without it the answer is `403 INSUFFICIENT_PROJECT_ROLE`.

Take `zone_id` from `GET /v1/projects/{projectId}/zone-scheme`, which needs `schedule:read`; see [Schedule, takt and deviations](/en/integrations/schedule-takt-and-deviations/#read-the-board-and-a-zone).

## Who recorded it

Each step and check the integration records names it: `inspected_by` is the integration's user, `created_via` is `integration` and `via_client_id` the integration's id. The app shows *Integration · {name}* on the inspection, in its history, on the zone's handoff list, in the PDF report and in the inspection a phone downloads for offline use. A verdict that an [app records for its person](/en/integrations/apps-for-a-person/) shows the person and the app, *{person} · via {app}*. When a person records the step again in the app, the step names that person.

A BCF export names the integration in the step finding's comments by its address, which ends in `.invalid` and receives no mail.

## Follow the changes

The lists `GET /v1/inspection-plans`, `GET /v1/inspection-plan-elements`, `GET /v1/templates` and `GET /v1/check-lists` work as the other lists; see [Collect changes in a window](/en/integrations/collect-changes/). A change to a template's steps changes the template, and a change to a plan's assignees changes the plan. Plan elements are the elements added by hand (`added`) and those left out (`excluded`); the elements the filter covers are read with the plan's `scope`.

Error codes are on [Errors and limits](/en/integrations/errors-and-limits/) and the fields in the [API reference](/en/api-reference/operations/createinspectionplan/).
