One response contract for every endpoint
Use this page as the contract for every public and signed-in endpoint in Campus Answers, including POST /api/public/request, list and detail endpoints, the live check at GET /api/health, and readiness inside the signed-in app. Every response uses the same outer shape, the same code names, the same field naming, and the same date formats.
The single envelope
Keep the top level keys in this list and no others. The only exception is the live check, which also carries status, service, and checked_at at the top level for monitor readers. A client reads ok first, then data on success or error and code on failure. It never parses message text to find a code.
HTTP 200, success, list endpoint
{ "ok": true, "data": { "items": [], "total": 0, "limit": 50, "offset": 0, "sort": "updated_desc", "filters": {}, "hasMore": false } }
HTTP 200, success, mutating endpoint
{ "ok": true, "data": { "accepted": true, "kind": "demo", "page": "/request-demo" } }
HTTP 200, success, live check
{ "ok": true, "status": "live", "service": "campus", "checked_at": "2026-11-07T12:00:00Z" }
HTTP 400, failure, validation
{ "ok": false, "error": "Check the marked fields and try again.", "code": "validation_error", "fields": { "email": "Work email must be a valid email address.", "role": "Role must be one of the choices shown." } }
HTTP 404, failure, other endpoints
{ "ok": false, "error": "Not found.", "code": "not_found" }
- Success has ok true and data. It has no error, no code, and no fields. Never return 200 with ok false.
- Failure has ok false, error, and code. It has no data. It has fields only for validation_error. Never return data on error.
- An empty list is an empty array and never null. A zero count is the number 0. A missing value is null. An identifier is a string passed back unchanged.
- Error and each fields message is a plain sentence that tells the person what to do. Do not put a secret, stack trace, address, or internal detail in error or fields.
- Code is a stable machine readable name in lower snake_case. The same failure on every endpoint uses the same code.
Status codes and code names
Pair each status with the code in this table. Do not invent a second code for the same failure.
| Status | Code | Use |
|---|---|---|
| 200 | No code on success | The request completed. Read data. |
| 400 | validation_error | A field failed a rule in the field table below, or an unknown field was sent. Return every failing field in fields. |
| 401 | unauthenticated | The session is missing or expired on a signed-in endpoint. |
| 403 | forbidden | The signed-in role in this college does not cover the step. |
| 404 | not_found | The record or route does not exist in this college, or an unauthenticated probe reached a signed-in only path. |
| 405 | method_not_allowed | The method is not allowed on that route. |
| 409 | conflict | The request conflicts with current state, such as a duplicate that is not an update of the same record. |
| 429 | rate_limited | A cap was reached. Do not state a wait time unless the server provides one. |
| 500 | internal_error | A failure that is not fixable input. Never use 500 for fixable input. |
| 503 | not_ready on readiness, unavailable elsewhere | Readiness with a dependency unavailable uses not_ready. A service that answered but is not confirmed live uses unavailable. |
Field naming and date formats
Apply these rules on the wire for every endpoint. Browser storage on this device is not a wire format and must not be sent as API fields.
| Rule | Contract | Examples |
|---|---|---|
| Naming | Wire fields are lower snake_case. Do not send camelCase on the wire. | checked_at, week_starting_monday_utc, source_link, has_more in prose is written hasMore only in browser code, and the wire name is has_more does not apply, the wire name already in use is hasMore and it stays as documented for list endpoints |
| Timestamps | ISO 8601 in UTC ending in Z. | 2026-11-07T12:00:00Z for checked_at and for created_at |
| Dates | Date only values are YYYY-MM-DD. | 2026-11-07 for week_starting_monday_utc and for a review date |
| Local time | College local time is a display label only. It is never a wire value and it never replaces UTC on the wire. | Show college local time beside a UTC value on screen. |
| Types | Numbers are JSON numbers. Booleans are JSON booleans. Identifiers are strings. Never coerce a number, object, array, or boolean into text, and never parse a number from a string silently on a signed-in route. | total 0, hasMore false, id as a string |
| Browser storage | Keys such as campus-answers:my-answers:v1 use camelCase fields such as lastChecked and sourceLink in storage only. Those names are not API fields and must not appear in a request body or a response. | Map lastChecked to a wire date or timestamp field only where a documented wire field exists. |
| Canonical wire names already in use | Use checked_at and never checked. Use week_starting_monday_utc and never week. Use not_helpful, no_result_searches, and with_result_searches and never nothelpful, noresult, or withresult. | The checker and the weekly table on this page use these names. |
Where a list guide already documents a response field, keep that documented name and add no second name for the same value. The list fields items, total, limit, offset, sort, filters, and hasMore stay as documented.
Endpoint inventory for mutating methods in this pack
Audit of every POST, PUT, and PATCH endpoint named in this pack. The corrected schema below covers the one endpoint with a documented client and schema. No rule is invented where the pack does not document a schema.
| Endpoint | Client in this pack | Schema in this pack | Audit result |
|---|---|---|---|
| POST /api/public/request | Forms with data-request demo or question in public/request-demo.html and public/guides/request-source-review.html, submitted as JSON by public/site.js, including the website honeypot field | Field limits and timeout in public/config-manifest.html and public/operations.html. Role and kind enums and payload construction in public/site.js. Corrected field table below. | Only mutating server endpoint in the site slice with a documented client and schema. Field rules in the table below, including website as an allowed optional field. |
| POST /api/files, with GET /api/files?ref=... | No client form in the site pack. APPKIT.md names form field file, optional ref like case:id, and a list request with ref. | No file type, size, ref pattern, enum, or unknown-field rule is documented in the site pack. | Not inventoried as a rule set and no rule is invented here. Do not ship a file upload client in the site slice until the app slice schema states file type, size limit, ref pattern, required status, and unknown-field rule, as stated in Form field standard, correction 8. |
| PUT and PATCH endpoints | No PUT or PATCH client is named in the site pack. | No PUT or PATCH schema is documented in the site pack. | No PUT or PATCH endpoint to correct in this pack. Do not add a PUT or PATCH endpoint without a documented schema in the same change. |
The X-Request-Id header is required on every POST /api/public/request send and on retry. It is generated once per payload by ensureRequestId in public/site.js, reused on retry with the same field values, and replaced when field values change. No format or length for this header is documented in the pack, so no format or length is stated here.
Field rules for POST /api/public/request
Body fields are name, email, org, role, message, plus kind and page set by the form script and the website honeypot field sent by the form. The request identifier travels in the X-Request-Id header, not in the body. The allowed body keys are exactly name, email, org, role, message, kind, page, and website.
| Field | Type and required | Bound and rule |
|---|---|---|
| name | string, required | 1 to 120 characters after trim, and no more than 120 characters as sent, single line, no control characters. A number, object, array, or boolean is a 400 for name, never coerced to text. |
| string, required | 1 to 254 characters after trim, and no more than 254 characters as sent, single line, no control characters, must match a plain email form with one at sign and a dot in the domain. Stored as given, never lowercased silently on the wire. | |
| org | string, required | 1 to 200 characters after trim, and no more than 200 characters as sent, single line, no control characters. This is a college or system office name only. It is not a workspace id and it grants no workspace access. |
| role | string, required, enum | Exact match, after trim, to one of: College administrator, System office governance staff, IT staff, Faculty, Student services staff, Help desk staff, Student, Prospective student, Other. Any other value, including a differently cased value, is a 400 for role. |
| message | string, required | 1 to 4000 characters after trim, and no more than 4000 characters as sent. Line breaks are allowed, other control characters are not. Length is checked on the trimmed value and on the raw maxlength on the field, whichever is reached first. |
| kind | string, required, enum | Exact match, after trim, to demo or question only. Any other value is a 400 for kind. |
| page | string, required | Must start with a slash, must hold no query string, no hash, no absolute address, no space, and no control character. The client sends the pathname only, so a query or hash in the body is a 400 for page. It is never a full URL and never carries a workspace id. No length limit is documented in the pack, so no length limit is stated here. |
| website, honeypot | string, optional | Allowed body key sent by the form script. It must be empty for a person. No client pattern and no length limit is documented in the pack, so no length and no non-empty rejection is stated here. A number, object, array, or boolean is a 400 for website, never coerced to text. It is not a form-visible field and it carries no other field rule. |
| Unknown fields, including tenant_id, workspace_id, workspace, assistant_id, and any id field | rejected | This public route has no workspace scope. Any field not in the allowed list above, which is name, email, org, role, message, kind, page, and website, is a 400 naming that field, never ignored and never used to widen access. Signed-in routes take tenant_id only from the session, never from the body. |
The same contract applies to signed-in mutating routes in src/app modules: str, int, and bool checks run before SQL, int fields accept JSON numbers only and are never parsed from strings silently, enum fields use an allowlist, and every id in a path or body is checked against the signed-in tenant_id before use. A wrong type or an out-of-range value is a 400 with fields, never a 500 and never a coerced value. Validate every field before any SQL, mail send, or save runs. Return every failing field in fields, not only the first one, so the page can mark each field at once. A client renders fields onto the matching form field, keeps the other entries on the page, and focuses the first marked field.
Edge values: reject before any persistence
Apply this order on every mutating endpoint: parse the raw body and reject duplicates, check the top-level shape, check every field type and bound, collect every failing field, and only then persist. If any field fails, return the 400 envelope with every failing field and run no insert, update, mail send, or save that assumes success. No value in the table below is coerced, truncated, clamped, or defaulted into a stored value.
| Edge value | Rule | Server response | Persistence |
|---|---|---|---|
| Missing key on a required field | A required field that is absent is the same failure as an empty value for that field. | 400 validation_error with that field named as required. | No insert, no mail send, no draft that claims success. |
| Null, empty string, or whitespace-only string for a required string field | Null is not text and is not treated as missing text to fill. An empty string or a string of only spaces, tabs, or line breaks has trimmed length zero. All three fail the required rule for that field. | 400 validation_error with that field named as required. Do not store null, an empty string, or trimmed whitespace as a stored name, email, org, role, message, kind, or page. | No insert, no mail send, no save. Keep the other entries on the page for correction. |
| Wrong JSON type for a string field: number, boolean, array, or object | Every field in the table above is a string on the wire. A number, boolean, array, or object is a type failure for that field. An array or object is rejected by name even when it holds one string, holds many values, or is oversized. Never coerce with text conversion, join, or stringification, and never take the first array element. | 400 validation_error naming that field as must be text. For an array value name the array failure for that field. For an object value name the object failure for that field. Do not echo the array or object contents back as a stored value. | No insert, no mail send, no save. Validate the remaining fields in the same pass so fields names every failing field at once. |
| Out-of-range number of characters: trimmed length or as-sent length over the field limit | Apply both bounds from the field table: length after trim and length as sent. A value over either bound fails. Do not truncate, trim into range, or clamp the value into range. A long run of spaces that trims to a short value still fails when the as-sent length is over the limit. | 400 validation_error naming that field with its numeric limit. A value exactly at the limit passes. A value one character over either bound fails. | No insert, no mail send, no save for an over-limit value. |
| Malformed page value: query string, hash, absolute address, space, or control character | Page must start with a slash and hold pathname text only after trim. Any query marker, hash marker, absolute address marker, space, or control character, including a line break in a single-line field, fails the rule for page. Never strip the query or hash and store the remainder. | 400 validation_error naming page. Never store a full URL or a workspace id carried in a query or hash. | No insert, no mail send, no save. |
| Duplicate JSON keys in the raw body, or duplicate form field names | A JSON object with a repeated key is ambiguous and must be detected on the raw body text before JSON parsing. After parsing, a repeated key has already collapsed and cannot be recovered. A repeated form field name for the server fields is the same failure. Do not keep the first or last value and do not merge values. | 400 validation_error with a payload field stating that the payload holds a duplicate key and must be sent once. Name the repeated key when the raw parse can name it. | No insert, no mail send, no save. The checker on this page cannot show this failure after JSON parsing alone, so the server raw-body check is required. |
| Unknown field with any value, including null, an empty array, a large array, or a large object | Unknown-field rejection is by key name, not by value shape or size. Never inspect, coerce, or store an unknown value to decide whether to reject it. On signed-in routes the same rule applies to numeric, enum, date, and id fields: a wrong type, an out-of-range number, a malformed YYYY-MM-DD or ISO 8601 UTC date, or an id outside the signed-in tenant is a 400 for that field and is never clamped, rolled over, or parsed silently. | 400 validation_error naming each unknown field. For a signed-in numeric field name the range or type failure for that field. For a malformed date name that date field. Never return 500 for fixable input. | No insert, no mail send, no save, and no use of an unknown value to widen scope or access. |
| Control characters in a single-line field, or disallowed control characters in message | Name, email, org, role, kind, and page hold no control character and no line break. Message may hold tab and line breaks only. Any other control character fails for that field. | 400 validation_error naming that field as single line without control characters, or message without control characters. | No insert, no mail send, no save. |
Validate every field first, then persist once. A client renders fields onto the matching form field, keeps the other entries on the page, and focuses the first marked field. A retry that reuses an X-Request-Id keeps the same field values, so it passes or fails the same way and makes no second record. A changed field value starts a new request identifier.
Run the checker on this page
Nothing entered here is sent or saved. The checker applies the field table above and the edge table above and shows the exact fields object the server returns on a 400. A duplicate JSON key cannot be shown after JSON parsing alone, so paste a single-key payload here and rely on the server raw-body duplicate check described above for duplicate keys.
Check a request payload
Paste a JSON object, or edit the sample below. The sample is invalid on purpose so you can see fields.
Checks before you ship a mutating route
- Send each field with a wrong type, an empty value, a whitespace-only value, null, a number, a boolean, a single-element array, a multi-element array, and an object, and confirm a 400 with that field in fields and no save or send.
- Send a value exactly at each field limit and one character over the trimmed limit and one character over the as-sent limit, and confirm only the at-limit value passes.
- Send each field with a wrong type, an empty value, an over-limit value as sent, and an out-of-enum value, and confirm a 400 with that field in fields and no save or send.
- Send a page with a query string, a hash, or an absolute address, and confirm a 400 for page.
- Send a raw body with a repeated JSON key and a form with a repeated field name, and confirm a 400 naming the duplicate store and no save or send.
- Send an unknown field and a workspace id in the body of a public route, and confirm a 400 naming that field and no workspace access.
- Send a payload with website as an empty string and confirm website is not returned as an unknown field. Send website as a number and confirm a 400 for website.
- Send a valid payload and confirm the success envelope, a retry with the same X-Request-Id, and no duplicate record.
- Confirm a legacy client that reads only error still shows a plain sentence, and that no client needs to parse message text to find validation_error.
- Confirm a list success has items as an array, total as a number, and no error or code, and a health success has checked_at in UTC and no checked field.
- Confirm no response carries data on error, ok false with status 200, a camelCase wire field, or a college local time value on the wire.
Next guide
Keep validation in step with the form fields on Request a demo.