The smallest possible create
Onlyname and groupId are required:
201 with the stored document and a Location header. Keep the _id — it is
what the update, delete and createAudit endpoints take.
The same endpoint also answers on
POST /api/v2/data/projects/{database}/audittemplates — the project-scoped
shape, which is the one to prefer in new code because it puts the project
where the read endpoints put it. One handler serves both URLs, so the request
and the response are identical either way, and both are supported
indefinitely. Every call in this recipe can be written either way; see Two
URL shapes for audits and audit templates.You need a template group first
groupId is mandatory, and must name an existing template group in the same
project. Find one with:
couchDbId, not id — id is the composite {database}|{couchDbId}
that the list endpoints return, and the write endpoints do not accept it.
If the project has no groups yet, create one — only name is required:
_id and couchDbId hold the same value, so either works as a template’s
groupId. The group is usable immediately — you do not have to wait for it
to appear in the group list above, which reads a search index and lags a few
seconds behind the write.
A group name has to be unused. Creating a second group with a name a live
group already has is a
409. The name is compared whole — “Handover” does not
collide with “Handover checks” — and after trimming. A name freed by deleting
a group can be reused.One caveat: the check reads the same search index the group list reads, and
that lags a write by a few seconds. Two creates of the same name fired
back-to-back can therefore both succeed. If you are importing groups in bulk,
de-duplicate your own input rather than relying on the 409.There is no endpoint to rename a group. A group’s name is copied onto every
template in it, so a rename has to update all of them — the app does that for
you, and the API does not offer a half-version of it. Renaming stays an in-app
action for now.What the server decides for you
The question tree
The tree is exactly two levels deep.questions holds categories, and
each category holds questions. There is no nesting beyond that.
categoryName and at least one question. A
bare question at the top level — where a category belongs — is rejected rather
than quietly absorbed.
The ten question types
settings.answertype takes one of ten values. The editor’s dropdown shows
eleven entries because multiplechoice splits in two through settings.choice.
An unrecognised
answertype is refused with 422. It is not coerced into
something else, so a typo fails loudly rather than producing a question of the
wrong kind.
Multiple choice
Options live insettings.richOptions, each with an id that
settings.answer refers to:
choicemust besingleormultiple, and is required for this type.- Option
ids must be unique within the question. A repeat silently merges two options into one, so it is rejected. - Every option needs text, an image, or both. An option with neither is not selectable and is refused.
- Older templates store option text directly in
settings.answerwith norichOptions. That still works and is still accepted — but userichOptionsfor anything new.
Yes/No/NA labels and colours
yesnona questions can carry per-template wording:
styling entirely and the app uses its defaults. Include it and all three
keys must be present with non-blank labels — the app reads all three, and a
missing one renders an unlabelled button.
The stored answer is always the platform’s own token (YES, NO, N/A),
never your label. Custom labels change what the auditor reads, not what you
read back.
Images
Two different features, two different fields. Both keep the picture on the document itself, as a CouchDB inline attachment — neither goes through Filestack or the attachment service. Attach the bytes once, base64-encoded, under_attachments:
- An image in the question body
- An image on a dropdown option
Static text
Astatictext block is an instruction to the auditor rather than a question.
Its own question field carries the literal string Ignored, and the body goes
in answer[0]:
Publish it
Only a published template can be used to create audits. Either publish at creation time withisPublished: true, or build the template first and publish
when it is ready:
dates.publishedDate for you.
Then create audits from it — see
Create an audit from a template.
Update
PATCH merges a whitelist: name, groupId, questions, tags,
isPublished, auditType, participants, answeredStatusEnabled,
recurrentAuditInfo, _attachments.
_rev.
Changing an existing template affects future audits only. Audits already
created from it keep the questions they were built with.
Concurrency
Someone editing the template in the Ed Controls app saves it whole, so a change you make from an older copy can overwrite theirs. Pass the_rev you last read
as If-Match to prevent that:
_rev fails with 409 and writes nothing — re-read, re-apply, retry.
Omit the header and the last write wins.
Archive
DELETE archives the template — the platform’s soft delete:
204, idempotent, and it honours If-Match. The template drops out of the
default lists, stays readable by id, and audits already created from it keep
working.
Errors
RFC 9457application/problem+json, whose detail names the offending path:
Authorization is evaluated before the body, so a
403 says nothing about
whether your JSON was valid.
Quirks worth knowing
These all cost someone time at least once.Is Duplicatable belongs to a category, not a question
Is Duplicatable belongs to a category, not a question
settings.duplicate — “Is Duplicatable?” in the Excel importer — controls
whether an auditor may repeat a category. Setting it on a question is
rejected with 422.If you are porting checklists from the audit-template spreadsheet, note it
uses one column for both category and question rows — so a value that sat
on a question row there has nowhere to go here.answer must be an array — never an empty string or null
answer must be an array — never an empty string or null
Every question carries
answer, and on a template it is normally [].
Sending "" or null is rejected.Worth watching if you build the tree by transforming your own data — an
empty value that serialises to "" rather than [] is the easy mistake,
and the app cannot read a template where it happens.Ids do not round-trip between list and by-id endpoints
Ids do not round-trip between list and by-id endpoints
The list endpoints return
id as the composite {database}|{couchDbId}.
Every by-id endpoint — read, update, delete, createAudit — takes the
bare couchDbId.Feeding an endpoint the id its own list just handed you does not work. Use
couchDbId, or split the composite on |.choice: null on a non-choice question is fine
choice: null on a non-choice question is fine
Stored documents carry
"choice": null on free-text questions, along with
"weightingfactor": null. Both are accepted. Only a real choice value
on a question that is not multiplechoice is refused, because that means
the type is wrong.A new template is not immediately searchable
A new template is not immediately searchable
The list and search endpoints read a search index, which the write reaches a
few seconds later.
POST returns 201 and the template is readable by id
at once, but it will not appear in GET /audittemplates immediately. Poll
rather than asserting straight after the write.auditType is not a closed set
auditType is not a closed set
area and object are the values the app offers, and area is the
default. point also appears in stored data. The API deliberately does not
enforce a list, because no two parts of the platform agree on one — send
area unless you have a reason not to.Who may do what
Note that read access is wider than write access: a Consulted, Informed,
Responsible or Reporter participant can see templates through the list and
by-id endpoints, and cannot change them.
