Guides · Administrator and support

Unified API response contract for success, error, list and detail responses

Use this contract to make every PermitDesk API response read the same way. It compares the response shapes already stated in this site pack, states one canonical envelope for new work, and keeps every existing field as an alias so current clients keep working.

How to read this page

Scope is limited to endpoints stated in this site pack. An endpoint not stated here is Unknown on this site. Do not rely on a shape for an endpoint until the town office supplies its name and a sample response from the app modules outside this site pack.

  • Canonical means the shape new endpoints must return and existing endpoints must add as aliases. It does not mean removing a field that a client already reads.
  • Every change in this contract is additive first. A field is removed only after the client that reads it is updated and a release note names the removal.
  • A response never returns a secret, key, token, vault item, card detail, connection string, internal address or build version. See Security.
  • Trimmed field selections and byte budgets for each endpoint are stated on API payload trimming and field selection. Use that page with this contract when you change a response shape.
  • Content type is part of the contract. Every API success and every API error returns a JSON body. An API error is never an HTML page. The health fallback to the home page is a page check, not an API response, and is not used for an API error.
  • Three corrections in this page override shorter summaries elsewhere. Health returns status ok only today. Error returns a top level sentence string only today. Status dates stay epoch milliseconds only today. Each correction names the reader gate that must pass before the field type changes.

Response shapes already stated in this site pack

Work down the table in order. Each row names the exact reader that states the shape, so a change can be checked against the reader before it ships.

Current success, error, list and detail shapes stated in the pack
Endpoint stated in packSuccess shape statedError shape statedID and timestamp format stated
POST /api/public/request, demo, question or pilot form, reader public/site.jsSuccess when the response is ok and the body is readable JSON. The form hides and a thank you state shows. No data object is stated.Failure when the status is not ok, or the body states ok false. The reader accepts error as a plain sentence string, and accepts code, requestId, request_id or diagnosticCode as the support code. It truncates the sentence and the code before display.No record ID is stated. No timestamp field is stated in the success body.
GET /api/public/records/status/{code}, reader public/status.htmlBody states ok true, a record object, a next_step value and a timeline list. Record fields stated are record_number, type_name, title, status, submitted_at, issued_at and closed_at. Timeline items state changed_at, new_status and public_message.Any non ok status, or a body that is not ok true with a record, shows one generic message that the code did not match a public status. No error code field is stated. The reader does not read an error body.Record identity is record_number, a business number, not a database ID. Dates are read as numbers and rendered as locale dates, so the stated format is epoch milliseconds, not an ISO string. A string date is rejected and shown as blank.
GET /healthz, dedicated health address, reader public/health.htmlAccepted only where the body is JSON and the status field is ok. The page then states the checked at time in UTC from the device clock.Any other body, a non JSON body, a timeout or a dropped connection shows public site did not serve a page. No error object is stated. The reader accepts only status ok. It does not accept ok true.No ID is stated. The checked at time is generated on the device, not read from the response.
POST /api/files and GET /api/files with ref, stated in APPKIT.mdUnknown: success envelope not in supplied site pack. Unknown: file object fields not in supplied site pack.Unknown: error envelope not in supplied site pack.Unknown: file ID format not in supplied site pack. Unknown: uploaded and listed timestamps not in supplied site pack.
Signed in list and detail endpoints under /api, not enumerated in this site packUnknown: list envelope and pagination fields not in supplied site pack, beyond the six filter fields and the list order stated on Reports and setup.Unknown: error envelope not in supplied site pack, beyond a plain sign in or role message stated on API authorization rules.Unknown: ID format and timestamp format not in supplied site pack for these endpoints.
  • Inconsistency 1, envelope. The form and status readers require ok, the health reader requires status ok, and file and signed in shapes are Unknown.
  • Inconsistency 2, error field type. The form reader requires error as a sentence string and a code at top level. A canonical error object cannot use the same top level error field at the same time as a string, so the object form is Phase 2 only, after the reader is updated.
  • Inconsistency 3, error code name. The form reader accepts four code field names, the status reader accepts no code field, and the health reader accepts no error body.
  • Inconsistency 4, time. Status dates are epoch milliseconds and a string date shows as blank, health time is an ISO string from the device, and no other timestamp format is stated.
  • Inconsistency 5, identity. Status uses a business record_number, and no endpoint in the pack states a database ID format.
  • Inconsistency 6, content type. Health checks that a health body is JSON and that a home fallback body is HTML. The form and status readers parse JSON. No page in the pack states a content type rule for an API error body, so an HTML error page would fail every API reader.

Canonical envelope for new work

Return this envelope for every new endpoint. Add it beside the existing fields on existing endpoints. Do not remove the existing fields in the same change. Phase 1 is the only phase that current readers accept today. Phase 2 starts only after the reader named in the gate is updated.

Canonical success, list, detail and error envelopes
KindCanonical shapeBackward compatible alias to keep
Success, detailok true, data as one object, and meta with request_id and checked_at.Phase 1 and Phase 2: keep the top level record, next_step and timeline fields that status.html already reads, with the same values as data, until that reader is updated to read data.
Success, listok true, data as a list of objects, and meta with total, page, page_size, request_id and checked_at. Total counts distinct records across all pages, not rows on one page.Keep any existing list field name as an alias of data with the same values, and keep the existing total field name as an alias of meta total, where a list already states one. Unknown for existing signed in lists until a sample is supplied.
Error, Phase 1 todayok false, top level error as one plain sentence string, top level code as one short fixed label in upper case with hyphens, data null or omitted, and meta with request_id and checked_at where the endpoint states them. The sentence tells the person what to do in one sentence.Keep code, requestId, request_id or diagnosticCode as the single top level code alias that site.js already accepts. Do not change error to an object in Phase 1. Site.js reads error as a string, so an object would be dropped and the person would see only a generic status message.
Error, Phase 2, after reader updateok false, error as one object with code, message and request_id. Code is a short fixed label in upper case with hyphens. Message is one plain sentence that tells the person what to do. Use the same HTTP status as the code class in the table below.Gate: site.js must read error.message and error.code first and the string form second. Until that gate passes, keep Phase 1 string and top level code beside the object only where a reader can ignore the object. Do not return an object alone in Phase 1.
HealthPhase 1 today: status ok at the top level for /healthz, with HTTP 200 and a JSON body. No other field is required by the reader.Gate: health.html must be updated to accept ok true second, after status ok first. Only after that gate passes may the server add ok true beside status ok. Never remove status ok until a release note names the removal date and the updated reader is live. Do not return ok true alone today.

Content type, HTTP status and body for every endpoint

Use this table for every endpoint stated in the pack. HTTP status and the ok field must agree in every row. A success status is 200 only. An error status is never 200.

Content type, status and body rule by endpoint
EndpointSuccess status and content typeError status and content typeBody rule
POST /api/public/request200, application/json, readable JSON, ok true400, 409, 422 or 500, application/json, readable JSON, ok false, Phase 1 error string and top level codeNever return an HTML error page. Never return 200 with ok false. Never return ok true with an error status. Keep the sentence short, because site.js truncates the displayed sentence and code.
GET /api/public/records/status/{code}200, application/json, readable JSON, ok true with a record404 or 500, application/json, readable JSON, same generic message for every unmatched code. No 401 and no 403 for this public lookup.The reader does not read the error body and shows one fixed generic message. The server message must therefore be generic for every unmatched code and must not state whether a record number exists. Never return a list of records.
GET /healthz200, application/json, readable JSON, status okAny other status, a non JSON body or a timeout is not a confirmed health result. No error object is stated.Do not return HTML as a health success. The home page fallback at / is a page with a HTML body and is not an API success. Do not add town data, a header, a version, a token or a secret to a health body.
POST /api/files and GET /api/files with refUnknown: success status and content type not in supplied site packUnknown: error status and content type not in supplied site packDo not assume a JSON body for these endpoints until a sample response is supplied. Record the sample in setup notes before this table is used for files.
Signed in list and detail endpoints under /apiUnknown: success status and content type not in supplied site pack, beyond 200 for a served request on API authorization rules401 and 403 as stated on API authorization rules, with a plain sign in or role message. Unknown: exact error body not in supplied site pack.Do not return record data from another workspace in an error body. Do not return a secret, token, vault item, card detail, connection string, internal address or build version in any body.

Per endpoint deviation and exact correction

Work down the table in order. Each row states the current deviation from one contract and the exact additive correction. No row removes a field that a current reader reads.

Current deviation and exact correction by endpoint
EndpointCurrent deviationExact correction, additiveGate before alias removal
POST /api/public/requestNo data object and no meta are stated. Error code may use four different top level names. The reader accepts only a string error and a top level code, not an error object.Add meta with request_id and checked_at beside ok. Keep error as a string and keep one top level code name per endpoint, chosen from code, requestId, request_id or diagnosticCode and recorded in setup notes. Add data null or omit data. Do not add record fields.Gate: site.js reads error.message and error.code first and the string form second. Only after that gate passes may error become an object, and only with a release note.
GET /api/public/records/status/{code}Top level record, next_step and timeline are used instead of data. Dates are epoch milliseconds only. No error code is read, and every non ok result shows the same generic message.Add data with the same record fields, next_step and timeline values, and add meta with request_id and checked_at. Keep the top level fields with the same values. Keep submitted_at, issued_at, closed_at and changed_at as epoch milliseconds on those field names. Return 404 with a generic JSON body for every unmatched code.Gate: status.html reads data first and the top level fields second, and accepts both epoch milliseconds and ISO strings for a date field. Only after that gate passes may a top level field be removed or a date field type change.
GET /healthzUses status ok instead of ok. The reader accepts only status ok and only a JSON body. No meta and no request_id are stated.Keep status ok and HTTP 200 and a JSON body. Do not add ok true alone. Add no town data and no new required field. A meta field may be added only where the health reader ignores unknown fields, and that ignore check must be recorded in setup notes first.Gate: health.html accepts status ok first and ok true second. Only after that gate passes may ok true be added beside status ok.
POST /api/files and GET /api/files with refSuccess envelope, error envelope, file object fields, file ID format and timestamps are all Unknown.No correction is applied to files until a sample success and a sample error response are supplied from the app modules. Record each sample field, its type and its content type in setup notes, then add data and meta beside the sample fields only.Gate: the signed in screen that reads files accepts data first and the sample fields second, and a release note names any removal.
Signed in list and detail endpoints under /apiList envelope, pagination, ID format, timestamp format and error envelope are Unknown, beyond the six filter fields and list order.No correction is applied to a named signed in endpoint until its name and a sample response are supplied. For new endpoints only, return ok, data and meta from the start, with snake_case record fields and meta total, page and page_size for a list.Gate: the screen that reads the list accepts data first and the sample fields second. Filters still narrow a list and never change sort order.

Exact response examples, additive phase

Examples show field names and field types only. Values in angle brackets are words from the record, not stored data. Phase 1 examples are the only examples current readers accept today.

Status success, Phase 1 plus canonical data alias. Keep record, next_step and timeline at top level with the same values as data.

{ "ok": true, "record": { "record_number": "value from record", "type_name": "value from record", "title": "value from record", "status": "value from record", "submitted_at": 0, "issued_at": 0, "closed_at": 0 }, "next_step": "value from record", "timeline": [ { "changed_at": 0, "new_status": "value from record", "public_message": "value from record" } ], "data": { "record": "same object as record", "next_step": "same value as next_step", "timeline": "same list as timeline" }, "meta": { "request_id": "value from server", "checked_at": "ISO UTC string from server" } }

Form error, Phase 1 today. Error is a string. Code is one top level name only.

{ "ok": false, "error": "one plain sentence telling the person what to do", "code": "VALIDATION_FAILED", "data": null, "meta": { "request_id": "value from server", "checked_at": "ISO UTC string from server" } }

Error, Phase 2 only after the site.js gate passes. Do not return this shape alone today.

{ "ok": false, "error": { "code": "VALIDATION_FAILED", "message": "one plain sentence telling the person what to do", "request_id": "value from server" } }

Health, Phase 1 today. Status ok only.

{ "status": "ok" }

List, new endpoints only. Existing signed in lists stay Unknown until a sample is supplied.

{ "ok": true, "data": [ { "record_number": "value from record" } ], "meta": { "total": 0, "page": 1, "page_size": 0, "request_id": "value from server", "checked_at": "ISO UTC string from server" } }

Status codes, field naming, IDs, timestamps and pagination

Use these rules for every endpoint. A rule that renames a field is not used, because renaming would break the readers in this pack.

Status codes and naming rules
RuleCanonical ruleWhat must not change
200, successRequest served for the signed in workspace and role, or for a public endpoint with no sign in. Body uses the success envelope above and a JSON content type.200 stays success for the form, status, health and file readers already stated. Health success also needs status ok.
400, invalid requestBody is missing, malformed or fails field validation. Error code VALIDATION_FAILED. Message names the field in plain words. Body is still JSON in Phase 1 string form.Do not use 400 for a sign in or role refusal. Those are 401 and 403 below.
401, unauthenticatedSign in is required or the session ended. Error code SIGN_IN_REQUIRED. Message tells the person to sign in again to the same workspace address.Do not return record data, a secret, a token or a vault item in the body. Do not use 401 for the public status lookup.
403, unauthorizedRole cannot use the action, or the record belongs to another workspace. Error code ROLE_NOT_ALLOWED or WORKSPACE_MISMATCH. Message says what the role can do instead.Do not return a record from another workspace. Workspace stays fixed, with no picker. Do not use 403 for the public status lookup.
404, not foundFor a status link code, show the same generic not found message for every unmatched code, as status.html does today, so the response does not state whether a record number exists.Do not list records and do not reveal a record from another workspace.
409, conflictRequest conflicts with current state, such as a duplicate submission for the same work. Error code DUPLICATE_REQUEST. Message names the existing record number where the record states one.Do not create a second record in the same request.
422, semantic validation failedFields are well formed but fail a business rule, such as a required item missing on a draft. Error code CHECKLIST_INCOMPLETE. Message lists each missing item by step and group in plain words.Do not use 422 for a malformed body. That is 400 above.
500, server errorRequest did not complete. Error code SERVER_ERROR. Message is one plain sentence. Log the request_id with user and time on the server, and never put a secret or a personal note in the message.Do not return a stack trace, an internal address, a connection string or a build version. Return a JSON body, not an HTML error page.
Field naming, IDs, timestamps and pagination
ItemCanonical ruleAlias and reader rule
Field namingKeep snake_case for record fields, as status.html already reads record_number, type_name, submitted_at, issued_at and closed_at. New record fields use the same snake_case style.Do not rename a field to camelCase in the same change. A client that reads snake_case must keep working.
ID formatBusiness identity stays record_number, assigned once at submission and never reused. Database IDs, where an endpoint states one, are opaque strings and are never parsed by the client.Keep record_number at the top level and inside data with the same value, until every reader reads data only.
Timestamp format, existing status fieldssubmitted_at, issued_at, closed_at and changed_at on the status endpoint stay epoch milliseconds today. Status.html accepts numbers only and shows a string date as blank.Do not change the type of those field names until status.html accepts both epoch milliseconds and ISO strings. An ISO alias, where needed, uses a new field name and is added beside the epoch field, never in place of it.
Timestamp format, new fieldsISO 8601 string in UTC, such as a date and time with a Z suffix, only on a new endpoint or a new field whose reader accepts ISO strings. One field name per event, for example checked_at in meta.Do not copy an ISO rule to a field whose reader accepts numbers only. The health checked at time is generated on the device and is not read from a response, so it is not a server timestamp field.
Pagination, listmeta total, meta page, meta page_size. Page starts at the first page with rows. Page size is stated on the list, or Unknown where the list does not state it, as on Query contract.Keep any existing page and total field names as aliases with the same values. A page past the last page with rows returns an empty data list with the same filters and total, not an error.
SortingSort is named on the list and is not set by filters. Keep the sort field name in meta where a list already states it.Do not change sort order in a contract change. Filters narrow a list, they never widen it.

Adopt the contract in order, without breaking clients

Work through these steps in order. Each step ends with what you should see when it worked.

  1. Add the canonical envelope beside existing fields, Phase 1 only

    Add data and meta beside the existing top level fields on existing endpoints. Keep error as a string, keep status ok, and keep epoch milliseconds on status date fields. You should see the old reader and a new reader return the same record, list or error.

  2. Fix content type and status agreement on every endpoint

    Return application/json for every API success and every API error, return 200 only with ok true or status ok, and return a non 200 status only with ok false. You should see no HTML error page from an API endpoint and no 200 with ok false.

  3. Normalize error code naming in Phase 1

    Choose one top level code name per endpoint from code, requestId, request_id or diagnosticCode, keep error as a string, and add meta request_id with the same value. You should see site.js show the same support code whichever alias the server returns, and no object error returned alone.

  4. Normalize timestamps without changing field types

    Keep epoch milliseconds on submitted_at, issued_at, closed_at and changed_at. Write ISO UTC strings only in new meta checked_at and only in new fields whose reader accepts ISO strings. You should see status dates still render on the status page.

  5. Normalize list pagination in meta, new lists first

    Add meta total, page and page_size to new lists first, keep existing total and page fields as aliases where a list states them, and confirm the total counts distinct records across all pages. You should see the card and the list show the same records with the same filters.

  6. Trim the field selection to the fields the reader uses

    Return only the keep fields in API payload trimming and field selection for each endpoint, record Content-Length on a test record beside the budget on that page, and confirm each screen still shows every field in the keep column. You should see a smaller response with the same screen result.

  7. Update readers, then move to Phase 2 in a later release

    Update site.js to read error.message and error.code first, status.html to read data first and both date types, and health.html to accept status ok first and ok true second. Remove a legacy alias only after the reader update is live and a release note names the removal date.

  8. Test on a test record, then publish

    Walk a test record through form submit, status lookup, file list and one signed in list. Check success, each error code in the table, empty list, page past the last page, content type on success and on error, and a draft that never appears in public search. You should see the same result from the old reader and the new reader before you publish.

Conformance check by endpoint
EndpointCheck in orderPass when
POST /api/public/requestRead status, content type and body. Submit a valid form and an invalid form on a test record.Valid submit is 200 with readable JSON and ok true. Invalid submit is a non 200 status with readable JSON, ok false, a string error sentence and one top level code. No HTML body and no 200 with ok false.
GET /api/public/records/status/{code}Read status, content type and body for a matched code and for an unmatched code.Matched code is 200 with ok true, a record, next_step, timeline and data with the same values, and epoch millisecond dates that render. Unmatched code is 404 with readable JSON and the same generic outcome as every other unmatched code, with no list and no existence leak.
GET /healthzRead status, content type and body with no sign in.Success is 200 with a JSON body and status ok. No ok true alone, no HTML body, no town data and no secret.
POST /api/files and GET /api/files with refSupply a sample success and a sample error response from the app modules first, then read status, content type and body against those samples.Unknown is replaced by a named sample in setup notes. No envelope is adopted until that sample passes the same status, content type and body checks.
Signed in list and detail endpoints under /apiSupply the endpoint name and a sample response first, then check 200, 401 and 403 with the workspace and role for the account.Unknown is replaced by a named sample in setup notes. An error body never returns a record from another workspace or a secret, token, vault item, card detail, connection string, internal address or build version.

API authorization rules · Query contract · Search a public record · Reports and setup

Bring your endpoint list to the demo

Tell us which list or record you need first, and we will confirm its envelope, status codes and pagination with your town role list.

Request a demo