Data API
Create, read, replace, patch and delete bucket documents over REST, with the permissions each endpoint needs and the responses it returns.
Every bucket has a REST API under /bucket/:bucketId/data. All examples use https://api.example.com/api as the public URL of the API.
Authentication
Send one of these headers with every request:
Authorization: IDENTITY <token>
Authorization: USER <token>
Authorization: APIKEY <key>The caller's policies must allow the endpoint's action on the bucket. For USER requests the bucket's rules are also applied.
| Endpoint | Action |
|---|---|
GET /bucket/:bucketId/data | bucket:data:index |
GET /bucket/:bucketId/data/:documentId | bucket:data:show |
POST /bucket/:bucketId/data | bucket:data:create |
PUT /bucket/:bucketId/data/:documentId | bucket:data:update |
PATCH /bucket/:bucketId/data/:documentId | bucket:data:update |
DELETE /bucket/:bucketId/data/:documentId | bucket:data:delete |
List documents
/bucket/:bucketId/datacurl "https://api.example.com/api/bucket/<bucketId>/data?limit=2&sort=%7B%22views%22%3A-1%7D" \
-H "Authorization: APIKEY <key>"[
{
"_id": "6b0b1972a5611972c29c25fd",
"title": "Hello Spica",
"slug": "hello-spica",
"status": "published",
"tags": ["intro", "news"],
"author": "6b0b1972a5611972c29c25fb",
"views": 42,
"created_at": "2026-11-28T18:12:02.224Z"
}
]| Query parameter | Description |
|---|---|
filter | An expression or a JSON filter. |
sort | JSON object of property names and 1 (ascending) or -1 (descending), for example {"views":-1}. |
limit | Maximum number of documents to return. |
skip | Number of documents to skip. |
paginate | When true, the response is {"meta": {"total": n}, "data": [...]}. |
relation | true to resolve every relation, or property paths such as author to resolve some. |
localize | Default true. Set to false to receive every language of translated properties. |
The Accept-Language header selects the language of translated properties, and the response's Content-Language header tells you which language was used. See Querying for details.
Get a document
/bucket/:bucketId/data/:documentIdAccepts relation and localize like the list endpoint. When a read rule hides the document from a user, the response is empty.
curl https://api.example.com/api/bucket/<bucketId>/data/6b0b1972a5611972c29c25fd?relation=author \
-H "Authorization: APIKEY <key>"Insert a document
/bucket/:bucketId/dataThe body is validated against the bucket schema. Defaults are applied and the stored document is returned:
curl -X POST https://api.example.com/api/bucket/<bucketId>/data \
-H "Authorization: APIKEY <key>" \
-H "Content-Type: application/json" \
-d '{
"title": {"en_US": "Hello Spica", "tr_TR": "Merhaba Spica"},
"slug": "hello-spica",
"status": "published",
"author": "6b0b1972a5611972c29c25fb"
}'{
"title": {"en_US": "Hello Spica", "tr_TR": "Merhaba Spica"},
"slug": "hello-spica",
"status": "published",
"author": "6b0b1972a5611972c29c25fb",
"views": 0,
"created_at": "2026-11-28T18:12:02.224Z",
"_id": "6b0b1972a5611972c29c25fd"
}Replace a document
/bucket/:bucketId/data/:documentIdReplaces the whole document. Properties you leave out are removed, and defaults are applied again. Returns the new document.
Patch a document
/bucket/:bucketId/data/:documentIdApplies a JSON merge patch. Properties you send are changed, properties set to null are removed, and everything else is kept. Returns the updated document.
curl -X PATCH https://api.example.com/api/bucket/<bucketId>/data/6b0b1972a5611972c29c25fd \
-H "Authorization: APIKEY <key>" \
-H "Content-Type: application/merge-patch+json" \
-d '{"views": 43, "cover": null}'Delete a document
/bucket/:bucketId/data/:documentIdReturns 204 No Content. When a relation property is marked dependent, the referenced documents are deleted too.
Several operations in one request
Combine several requests into one round trip with the batch endpoint:
{
"requests": [
{"id": "1", "method": "POST", "url": "bucket/<bucketId>/data", "body": {"title": {"en_US": "One"}, "slug": "one"}, "headers": {"Authorization": "APIKEY <key>"}},
{"id": "2", "method": "POST", "url": "bucket/<bucketId>/data", "body": {"title": {"en_US": "Two"}, "slug": "two"}, "headers": {"Authorization": "APIKEY <key>"}}
]
}Errors
| Status | When | Example message |
|---|---|---|
400 | The document doesn't match the schema, or a unique index is violated. | .slug must match pattern "^[a-z0-9-]+$" |
401 | The Authorization header is missing or invalid, or a write rule rejects the operation. | No auth token, ACL rules has rejected this operation. |
403 | A policy denies the operation. | You do not have sufficient permissions to do bucket:data:index on resource <bucketId> |
404 | The bucket or document doesn't exist. | Could not find the schema with id <bucketId> |
Engine differences
On PostgreSQL:
- Documents are identified by the bucket's primary property instead of
_id. Use its value as:documentId. bigintvalues are returned as strings.- Filters must be expressions. JSON filters are rejected.
See MongoDB and PostgreSQL for the full list.
From code
The bucket devkit wraps these endpoints:
import * as Bucket from "@spica-devkit/bucket";
Bucket.initialize({apikey: process.env.API_KEY, publicUrl: "https://api.example.com/api"});
const posts = await Bucket.data.getAll(POSTS_BUCKET_ID, {
queryParams: {filter: 'document.status == "published"', sort: {created_at: -1}, limit: 10}
});