Create and update validation for every endpoint
Use one server-side validation rule for each create and update endpoint in the signed-in app. Check required fields, data types, enums, string lengths, and numeric bounds before any write, and return one consistent error shape for 400 and 409 responses.
Response rules for every endpoint
Apply these rules before endpoint-specific rules. Keep the same shape on every create and update endpoint. These rules use the canonical envelope and status table in APPKIT.md and on the API response standard page. There is no 422 in this pack. Every validation failure below is 400 with code validation_error.
| Case | Status | Error code | Message |
|---|---|---|---|
| Malformed JSON, wrong content type, or unreadable body | 400 | validation_error | Request body is not valid JSON. |
| Unknown field present | 400 | validation_error | Field is not supported for this endpoint. |
| Required field missing or empty after trimming | 400 | validation_error | Field is required. |
| Wrong data type, invalid enum, invalid date, or invalid URL | 400 | validation_error | Field has the wrong type or an unsupported value. |
| String longer than the stated limit | 400 | validation_error | Field is longer than the allowed length. |
| Number outside the stated bounds, or non-integer where an integer is required | 400 | validation_error | Field is outside the allowed range. |
| Duplicate create that matches an existing record on the stated key | 409 | conflict | A record with the same key already exists. |
Response body shape for every 400 and 409 response, and for every JSON error: { ok: false, error: a plain sentence telling the person what to do, code: validation_error for 400 or conflict for 409 }. Servers write only this envelope. error stays a plain string and is never an object. A client derives the code name from the status table and must not parse message text. Do not add a fields object on the wire in place of the plain string. For builder tests, the field names that failed validation are sorted by field name in the test expectation. Return no stack trace, no secret, and no question text from another workspace in an error.
- Trim leading and trailing space on every string before the required check and the length check. Reject a string that is empty after trimming where the field is required.
- Reject null for a required field. Treat an omitted optional field as no value, and treat a present null for an optional string as empty.
- Reject numbers sent as strings, booleans sent as strings, and arrays or objects sent where a string is required. Do not coerce types.
- Reject a duplicate field name in the raw JSON as 400 validation_error.
- Check validation before permission to list a specific record is granted, and check permission before any write. A failed validation returns no partial write.
- GET endpoints in this pack have no POST, PUT, or PATCH validation. List params q, limit, offset, and sort use the fallbacks in APPKIT.md and are not 400 errors. No PUT or PATCH endpoint is documented in this pack. A future PUT or PATCH endpoint must use this table and must be added as a row below before it ships.
Endpoint rules by resource
Each row states the create rule and the update rule. Update uses the same field rules, and a field sent on update replaces the stored value only when it passes validation. The first two rows are the only POST endpoints documented in the site slice of this pack. The remaining rows are browser-local and signed-in resources whose client validators are in this pack.
| Endpoint resource | Required fields and limits | Types, enums and numeric bounds |
|---|---|---|
| POST /api/public/request, create | name string 1 to 120, email string 1 to 254, org string 1 to 200, role string 1 to 120, message string 1 to 4000, kind enum demo or question, page string starting with / and at most 500. website honeypot string must be empty when present. X-Request-Id header string 1 to 120, required, and reused on retry. | All body fields string, no coercion. role enum College administrator, System office governance staff, IT staff, Faculty, Student services staff, Help desk staff, Student, Prospective student, Other only. email must match a single-line address with no space and no control character. name, email, org, and role must have no control character and no line break. message allows tab, line feed, and carriage return only among control characters and no other control character. Any other field returns 400 validation_error. Missing checks to add server side: re-check every field above before any write or reply, because the client check in public/site.js must not be trusted, reject duplicate JSON keys, reject a non-empty honeypot, and reject a kind or page that does not match the form that was shown. |
| POST /api/files, create | file part required and non-empty. ref optional string in the form type colon id, for example case colon id, at most 120. | file must be a file part, not a string field. ref type must be an allowlisted record type for this workspace and ref id must name a record in this workspace. Any field other than file and ref returns 400 validation_error. Missing checks to add server side: this pack documents no file size limit, no accepted mime list, and no ref type allowlist for this endpoint, so confirm those three values from the signed-in app source before shipping and do not invent them here. Until they are documented, reject an empty file, reject a ref that does not parse, and reject a ref whose type is not allowlisted, rather than storing the file unscoped. |
| Saved answer, create and update | title string 1 to 200, collectionId string 1 to 120 and must be a known collection id, with unfiled as the default. Optional question 0 to 2000, answer 0 to 4000, sourceTitle 0 to 200, sourceLink 0 to 500, lastChecked 0 to 80, workspace 0 to 120, assistant 0 to 120. | All fields string. sourceLink must start with http:// or https:// when present. reaskCount integer 0 to 1000000 when present on update. Duplicate key is title plus question plus sourceLink plus workspace plus assistant, and returns 409 conflict on create. |
| Share copy and import file, create | title string 1 to 200. Optional question 0 to 2000, answer 0 to 4000, sourceTitle 0 to 200, sourceLink 0 to 500, lastChecked 0 to 80, workspace 0 to 120, assistant 0 to 120, collection 0 to 80, savedDate 0 to 10. | All fields string. sourceLink must start with https:// when present. savedDate must match YYYY-MM-DD and must be a real calendar date when present. |
| Canonical eligibility record, create | college string 1 to 120, assistant string 1 to 120, topic string 1 to 200, sourceTitle string 1 to 200. All six condition fields are required. | Condition fields are enum yes or no only. No other value is accepted. result is server computed from the six conditions and is never accepted from the client. |
| Role first-run progress, create and update | college string 1 to 120, role string 1 to 40, checked object with at most 5 keys. Each key string 1 to 20. | role enum visitor, student, instructor, admin only. Each checked value must be boolean true. completedAt and snoozedUntil must be ISO 8601 UTC with Z when present, and snoozedUntil must be after the request time. |
| Weekly quality outcome, create | event string 1 to 60, week_starting_monday_utc string 10 in YYYY-MM-DD form. One event-specific field is required as stated in the next column. | event enum campus_feedback_given, campus_answer_shown, campus_guide_search_performed only. rating enum helpful, not_helpful required for campus_feedback_given. outcome enum not_answered required for campus_answer_shown. result_bucket enum no_result, with_result required for campus_guide_search_performed. workspace, assistant and channel must be string or null, and each string is 0 to 120 when present. id string 1 to 120 is required and unique, and a duplicate id returns 409 conflict. |
| Campaign attribution, create and update | Each of utm_source, utm_medium, utm_campaign, utm_term, utm_content and utm_id is optional string 0 to 120. | Each value must match letters, digits, dot, underscore or hyphen only. source_page string 1 to 500 must start with / when present. referrer_origin enum same_site, external, none only. Any other field returns 400 validation_error. |
| Collection, create and update | name string 1 to 80 on create. id string 1 to 120 on update. | All fields string. The built-in collection id unfiled cannot be renamed or deleted, and an update that targets it returns 400 validation_error with field id. |
Checks before you ship a validation change
Send each payload below to the endpoint and confirm the stated status, code, and field list.
- Empty title, missing college, and a string one character over its limit each return 400 with code validation_error and the field named.
- A number sent as a string, an enum value outside its list, and a source link without http or https each return 400 validation_error with the field named.
- An unknown field returns 400 validation_error, malformed JSON returns 400 validation_error, and a duplicate create returns 409 conflict, all with the same body shape.
- POST /api/public/request: each of an empty name, an email with a line break, a role outside the enum, a message one character over 4000, an unknown field, and a non-empty honeypot returns 400 validation_error and writes nothing. A valid payload with a reused X-Request-Id on retry creates no second request.
- POST /api/files: a missing or empty file, an unparseable ref, and an unknown field each return 400 validation_error and store nothing.
- A valid create writes once, a valid update replaces only the sent fields, and a failed validation writes nothing.
- No error response contains a stack trace, a secret, question text from another workspace, or a full referrer address.
Next guide
Keep form field wording consistent with these limits.