Skip to main content

REST API reference

NextBase serves a REST API under the route you mount it at, by default /api/nextbase. Requests and responses are JSON. Every path in this reference is relative to that.

AreaPaths
Records/collections/{collection}/records
Auth/collections/{collection}/auth-with-password, /session, /sessions
Collections/collections (superusers)
Setup and health/setup, /health

Authentication​

Send the session token from signing in in the Authorization header (a "Bearer token"):

Authorization: Bearer <token>

or sign in with a session cookie, which the browser sends on its own. If both are present, the header wins.

  • An invalid or expired Bearer token is a 401.
  • An invalid cookie is removed and the request continues signed out.
  • A write (POST, PATCH, DELETE) authenticated by the cookie must send an Origin header naming the same host, or it gets a 403. Browsers do this on their own.

Requests​

Request bodies are JSON (Content-Type: application/json), up to 1 MiB.

Errors​

Every error has the same shape:

{
"status": 400,
"message": "Failed to create the record.",
"data": {
"title": { "code": "validation_required", "message": "Cannot be blank." }
}
}

data holds field errors, keyed by field and nested for nested input. code is stable and meant for programs; message is for people.

StatusMeaning
400invalid input, a failed create rule, or a bad filter
401missing or invalid credentials where they are required
403the action needs a superuser, or a cross-site cookie write
404not found, or hidden by a rule
405method not allowed
409conflict with a concurrent change; retrying works
413request body too large
415request body is not JSON
429too many failed sign-in attempts
500unexpected server error, logged on the server

Field error codes​

CodeMeaning
validation_requiredthe value is empty
validation_invalid_valuethe value is not allowed
validation_invalid_typethe value has the wrong type
validation_invalid_formatthe value does not match the pattern
validation_invalid_email, validation_invalid_urlnot an email or URL
validation_domain_not_allowedthe email or URL domain is not allowed
validation_length_out_of_rangetext too short or too long
validation_out_of_rangenumber or date out of range
validation_not_integerthe number must be whole
validation_too_manytoo many values selected
validation_too_largeJSON value too large
validation_not_uniquethe value is already taken
validation_missing_relationa related record does not exist
validation_values_mismatchpasswordConfirm differs from password
validation_invalid_old_passwordoldPassword is missing or wrong
validation_forbiddenonly superusers may change this field
validation_invalid_rulea rule does not compile