REST API
Every PocketOne app serves a JSON API under /api/: its collections' records, signing in, files, realtime and, for
superusers, the admin endpoints the dashboard uses. The JavaScript SDK
wraps it, but anything that speaks HTTP can use it.
| Area | What it covers |
|---|---|
| Records | list, view, create, update and delete a collection's records |
| Authentication | sign in, refresh, sign up flows, verify, reset, change email, impersonate |
| Realtime | subscribe to record changes over server-sent events |
| Files | download files and thumbnails, protected-file tokens |
| Batch | several record writes in one transaction |
| Collections | create and change collections (superusers) |
| Settings | the app's settings, test mail and S3 (superusers) |
| Logs | request and app logs (superusers) |
| Crons | list and run scheduled jobs (superusers) |
| Backups | make, download, upload and restore backups (superusers) |
| SQL | run a SQL query (superusers) |
| Health | is the app up |
| Extension APIs | the endpoints PocketOne's extensions add, under /api/_c/ |
Requests
The base URL is your app's address: https://myapp.example.com/api/..., or http://127.0.0.1:8090/api/... locally.
Send JSON bodies with Content-Type: application/json, or multipart/form-data when you upload files.
Auth
Sign in through an Authentication endpoint and you get a token. Send it as the
Authorization header, with or without Bearer :
curl http://127.0.0.1:8090/api/collections/posts/records \
-H "Authorization: eyJhbGciOiJIUzI1NiJ9..."
A request with no token is a guest. What each request may do is decided by the collection's API
rules; endpoints marked superusers need a token from the _superusers collection. An API
token works the same way for scripts and other apps.
Lists
Every list endpoint takes the same query parameters:
| Parameter | Does | Example |
|---|---|---|
page |
the page, from 1 | page=2 |
perPage |
items per page, up to 1000 (default 30) | perPage=100 |
sort |
fields, - for descending, @random for random order |
sort=-created,title |
filter |
a filter | filter=(published=true && title~'hello') |
expand |
relations to include, nested with dots, up to 6 levels | expand=author,comments_via_post.author |
fields |
only these fields in the answer; * for all at a level, :excerpt(200,true) to shorten |
fields=id,title,expand.author.name |
skipTotal |
skip counting totalItems and totalPages (faster for big tables) |
skipTotal=1 |
A list answers:
{
"page": 1,
"perPage": 30,
"totalItems": 2,
"totalPages": 1,
"items": [{ "id": "...", "collectionName": "posts", "title": "Hello" }]
}
URL-encode filter and sort values in real requests (curl --get --data-urlencode does it for you).
Errors
Errors answer with a status and a JSON body:
{
"status": 400,
"message": "Failed to create record.",
"data": {
"title": { "code": "validation_required", "message": "Cannot be blank." }
}
}
| Status | Means |
|---|---|
| 400 | the request is invalid; data names each field's problem |
| 401 | the endpoint needs auth and the request has none (or its token is invalid) |
| 403 | the request's auth may not do this |
| 404 | not found, or a rule hides it (so ids don't leak) |
| 429 | too many requests (rate limits, set in Settings) |
Next
- Records: the endpoints most clients use.
- API rules and filters: who may call what.
- Custom routes: add endpoints of your own.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.