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:

HTTP
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.

EndpointAction
GET /bucket/:bucketId/databucket:data:index
GET /bucket/:bucketId/data/:documentIdbucket:data:show
POST /bucket/:bucketId/databucket:data:create
PUT /bucket/:bucketId/data/:documentIdbucket:data:update
PATCH /bucket/:bucketId/data/:documentIdbucket:data:update
DELETE /bucket/:bucketId/data/:documentIdbucket:data:delete

List documents

GET/bucket/:bucketId/data
Terminal
curl "https://api.example.com/api/bucket/<bucketId>/data?limit=2&sort=%7B%22views%22%3A-1%7D" \
  -H "Authorization: APIKEY <key>"
JSON
[
  {
    "_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 parameterDescription
filterAn expression or a JSON filter.
sortJSON object of property names and 1 (ascending) or -1 (descending), for example {"views":-1}.
limitMaximum number of documents to return.
skipNumber of documents to skip.
paginateWhen true, the response is {"meta": {"total": n}, "data": [...]}.
relationtrue to resolve every relation, or property paths such as author to resolve some.
localizeDefault 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

GET/bucket/:bucketId/data/:documentId

Accepts relation and localize like the list endpoint. When a read rule hides the document from a user, the response is empty.

Terminal
curl https://api.example.com/api/bucket/<bucketId>/data/6b0b1972a5611972c29c25fd?relation=author \
  -H "Authorization: APIKEY <key>"

Insert a document

POST/bucket/:bucketId/data

The body is validated against the bucket schema. Defaults are applied and the stored document is returned:

Terminal
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"
  }'
JSON
{
  "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

PUT/bucket/:bucketId/data/:documentId

Replaces the whole document. Properties you leave out are removed, and defaults are applied again. Returns the new document.

Patch a document

PATCH/bucket/:bucketId/data/:documentId

Applies a JSON merge patch. Properties you send are changed, properties set to null are removed, and everything else is kept. Returns the updated document.

Terminal
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

DELETE/bucket/:bucketId/data/:documentId

Returns 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:

JSON
{
  "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

StatusWhenExample message
400The document doesn't match the schema, or a unique index is violated..slug must match pattern "^[a-z0-9-]+$"
401The Authorization header is missing or invalid, or a write rule rejects the operation.No auth token, ACL rules has rejected this operation.
403A policy denies the operation.You do not have sufficient permissions to do bucket:data:index on resource <bucketId>
404The 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.
  • bigint values 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:

TypeScript
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}
});