Skip to content

Get started with API

Krzysztof Słysz edited this page Nov 23, 2026 · 24 revisions

Get started with API

Everything you can do with data in the Databucket web application, you can also do through the REST API: insert, search, modify, reserve and delete data. This page shows how to sign in and how to call the data endpoints. AI agents can use the same token with the MCP server. In the examples, <databucket url> is the address of your Databucket server, e.g. http://localhost:8080.

API documentation (Swagger)

The full API specification is served by your Databucket server:

  • Swagger UI: <databucket url>/swagger-ui/index.html
  • OpenAPI specification (JSON): <databucket url>/v3/api-docs

To try the data API in the Swagger UI: sign in with POST /api/public/signin ("Try it out"), copy the token from the response, click Authorize, paste the token and confirm. The next "Try it out" requests send it. The Swagger UI lists only the public API: signing in and the bucket data operations.

Before you start

To use the data API you need a Databucket user who:

  • signs in with a user name and password, or - when single sign-on is enabled - with a client token from the provider (see Single sign-on → Robots; required when the password sign-in is switched off). Accounts of people who sign in through SSO are meant for the web application. For tests and other automation, create a dedicated user, e.g. with the ROBOT role,
  • has the AGENT role or higher; deleting data and clearing the history need ROBOT or higher (see Roles & permissions),
  • is assigned to the project and has access to the bucket.

Sign in

Send the user name and password to POST <databucket url>/api/public/signin. Add projectId when the user is assigned to more than one project:

{
  "username": "robot",
  "password": "secret",
  "projectId": 1
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiJ9...",
  "username": "robot",
  "project": {
    "id": 1,
    "name": "Demo",
    "description": null,
    "enabled": true,
    "expired": false
  },
  "roles": ["ROBOT"]
}
  • When the user is assigned to one project, you can omit projectId; the user is signed in to that project.
  • When the user is assigned to several projects and projectId is omitted, the response contains no token, only the list of the user's projects. Sign in again with one of their ids.
  • Wrong user name or password, or a disabled user: 401. Expired user, disabled or expired project, or a project the user is not assigned to: 403. The reason is in the message field.
  • When the user has to change the password, the response contains "changePassword": true instead of a project. Sign in to the web application once and change the password.

Call the API

Send the token in the Authorization header of every request:

Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

The server checks the rules of the data requests and builds the SQL safely (see Rules). The header Databucket-Api-Version: 2, needed from 3.13.0 to 3.16.x, is ignored since 3.17.0.

The token is valid for the number of hours set in jwt.expire.hours (24 in the example configuration, see Installation). There is no refresh token: when the token expires, the API answers 401 and you sign in again. The token is bound to the project you signed in to; to work with another project, sign in with its projectId.

Data endpoints

All data endpoints start with <databucket url>/api/bucket/{bucketName}, where {bucketName} is the bucket name.

Method Path Body What it does
POST /api/bucket/{bucketName} data Inserts one data row
POST /api/bucket/{bucketName}/multi array of data Inserts several data rows, in one transaction: all of them or none
POST /api/bucket/{bucketName}/generate generators Generates random data rows on the server and inserts them (see Generating data)
GET /api/bucket/{bucketName}/{ids} Gets data by ids, e.g. /12 or /12,13,14
POST /api/bucket/{bucketName}/get rules, columns Gets data matching the rules
PUT /api/bucket/{bucketName}/{ids} changes Modifies data by ids
PUT /api/bucket/{bucketName} changes and rules Modifies data matching the rules
POST /api/bucket/{bucketName}/reserve rules Reserves data matching the rules
DELETE /api/bucket/{bucketName}/{ids} Deletes data by ids
DELETE /api/bucket/{bucketName} rules Deletes data matching the rules

The data body has these optional items: tagId, reserved and properties (any JSON object). When modifying data, properties replaces all the properties, and reserved: true changes only the rows that are not reserved yet (a row reserved by someone has to be released first). To change only some of them, use propertiesToSet (an object of JSON paths and values, e.g. {"$.address.city": "Paris"}) and propertiesToRemove (a list of JSON paths, e.g. ["$.phone"]) instead.

Modifying and deleting by rules require at least one rule, so that you don't change the whole bucket by accident.

/get and /reserve accept these query parameters:

  • limit - how many data rows to return or reserve, 1 by default. For /get, limit=0 returns only the number of matching rows (total); for /reserve, limit=0 reserves nothing and returns only the number of free rows matching the rules (available).
  • page - (/get only) the page number, 1 by default.
  • sort - the order, id by default. Use a field or property name, optionally wrapped in asc() or desc(), e.g. sort=desc(modifiedAt) or sort=$.lastName. Properties are sorted by their value (numbers as numbers). Use sort=random for a random order.
  • count - count=false skips counting: /get (since 3.18.1) returns the page without total and totalPages, /reserve (since 3.16.3) reserves without counting the free rows that still match (no available). Counting reads every matching row: when many rows match, it takes most of the time of the request (e.g. 1 million rows, 650,000 matching: a page in about 30 ms instead of 195 ms), so use count=false when you don't need the number - for example for the next pages of the same rules. true by default; limit=0 always counts.

How to write rules is described on the Rules page, and columns on the Custom columns page.

The reserve response says how many rows were reserved (reserved), how many unreserved rows still match the rules (available, counting all free rows, also in a bucket with protected data; not with count=false), and contains the reserved rows (data). A user with the ADMIN role can reserve data for another user with targetOwnerUsername in the body.

In a bucket with protected data, users without the ADMIN role can see and change only the data they reserved.

Generating data

Since 3.20.0, POST /api/bucket/{bucketName}/generate makes up to 10 000 random rows on the server and inserts them in one transaction - you send a generator for each property instead of the rows. The generators are the same as in the web application and in the MCP tool generate_data (the full list is there).

{
  "count": 1000,
  "locale": "pl",
  "seed": 42,
  "fields": {
    "$.login": "user-{n}",
    "$.firstName": "#{Name.firstName}",
    "$.address.city": "#{Address.city}",
    "$.age": {"number": [18, 90]},
    "$.balance": {"number": [0, 5000], "decimals": 2},
    "$.status": {"oneOf": ["active", "blocked"], "weights": [9, 1]},
    "$.birthDate": {"date": ["1950-01-01", "2005-12-31"]},
    "$.type": "customer"
  }
}
  • fields - property path → generator; count - 1 to 10 000.
  • locale (en by default), seed (the same rows again), tagId, reserved - optional.
  • startN - the number {n} of the first row; by default it continues after the last id of the bucket, so {n} stays unique between calls.

The response (201) has the number of inserted rows, the range of {n} used and the first 3 rows: {"inserted": 1000, "firstN": 1, "lastN": 1000, "rows": [...]}. With ?preview=true nothing is inserted and the response (200) has the first rows, at most 10 - with a seed, the same rows a call without preview then inserts. An invalid generator, count or tagId gives 400 with a message naming the field. The same access as for inserting data (AGENT and up).

Running a task

Since 3.21.0 a test or a script can run a task saved in the project settings, so the change lives in one place (the task) instead of in every test:

POST /api/bucket/{bucketName}/tasks/{taskId}/run

The task runs on the rows matching its filter and the rules of the body together. The body is optional when the task has a filter; a task without a filter needs rules, so it never runs on the whole bucket by mistake:

{
  "rules": [
    ["modifiedAt", "<", "@now-2h"]
  ]
}

The task id is in the column Id of Settings → Tasks; the MCP server lists the tasks of a bucket, with their ids, in describe_bucket. The response says what the task did:

{"taskId": 3, "task": "trash used", "action": "modify", "preview": false, "count": 12, "message": "Modified 12 data row(s)"}
  • ?preview=true changes nothing: count is the number of rows the task would run on (for reserve, the rows it would reserve, and available the free rows).
  • reserve also returns available, the free rows still matching. As in the web application, an ADMIN reserves for the user set in the task, other users for themselves.
  • Tasks removing rows or clearing the history need ROBOT or higher (403 otherwise); the others AGENT and up, with access to the bucket.
  • 404 - no such bucket, or the task isn't one of the bucket's tasks (Show in buckets / Show by classes); 406 - no filter and no rules, the task changes nothing, or the bucket keeps no history; 400 - invalid rules.

To run a task regularly, add a job with a cron instead of a cron job of your own. To run several tasks in one call (e.g. DEV cleaning before the tests), give the jobs a keyword and call POST /api/task-schedules/run with {"keyword": "DEV cleaning"} - see Jobs (since 3.23.0).

Data history

In buckets with history (see Data history) these endpoints are open to MEMBER and ROBOT accounts (ROBOT since 3.14.0); AGENT accounts (since 3.15.0) can read and search the history, but not clear it:

Method Path Body What it does
GET /api/bucket/{bucketName}/{id}/history The changes of a data row, oldest first
GET /api/bucket/{bucketName}/{id}/history/{historyIds} The properties of the row in the given history entries
DELETE /api/bucket/{bucketName}/{id}/history/clear Clears the history of a data row
DELETE /api/bucket/{bucketName}/history/clear rules Clears the history of the data matching the rules
POST /api/bucket/{bucketName}/history/get rules, historyRules Searches the history (since 3.14.0)

The search takes:

  • rules - which data rows, by their current state, as for /get; without them the history of all rows,
  • historyRules - which history entries, written as Rules on the fields of the entries: id (of the entry), dataId, tagId, reserved, modifiedBy, modifiedAt. The properties of past versions can't be searched,
  • query parameters page, limit (20 by default, at most 1000; 0 returns only total), sort (one of the fields above, e.g. desc(modifiedAt)) and properties=true to get the properties of each version.

For example, the changes made by nightly-robot since 1 November on the rows that are now in Great Britain, newest first:

curl -X POST "http://localhost:8080/api/bucket/users/history/get?limit=50&sort=desc(modifiedAt)" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"rules": [["$.address.country", "==", "GB"]],
       "historyRules": [["modifiedBy", "==", "nightly-robot"], ["modifiedAt", ">=", "2026-11-01T00:00:00.000Z"]]}'
{"page": 1, "limit": 50, "sort": "desc(modifiedAt)", "total": 2, "totalPages": 1, "history": [
  {"id": 3215, "dataId": 716, "propertiesChanged": true, "modifiedAt": "2026-11-07T23:00:00.000Z", "modifiedBy": "nightly-robot"},
  {"id": 3120, "dataId": 716, "reserved": true, "propertiesChanged": false, "modifiedAt": "2026-11-05T08:12:00.000Z", "modifiedBy": "nightly-robot"}
]}

Only the items that changed are set: tagId and reserved show the new value, propertiesChanged whether the properties changed.

Example with curl

Sign in and keep the token:

TOKEN=$(curl -s -X POST <databucket url>/api/public/signin \
  -H "Content-Type: application/json" \
  -d '{"username": "robot", "password": "secret", "projectId": 1}' | jq -r .token)

Insert a data row:

curl -X POST <databucket url>/api/bucket/users \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"properties": {"firstName": "John", "lastName": "Lennon", "active": true}}'

Get up to 10 active users, the newest first:

curl -X POST "<databucket url>/api/bucket/users/get?limit=10&sort=desc(id)" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"rules": [["$.active", "==", true]]}'

Reserve one unreserved active user:

curl -X POST "<databucket url>/api/bucket/users/reserve?limit=1" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"rules": [["reserved", "==", false], ["$.active", "==", true]]}'

Delete the data row with id 12:

curl -X DELETE <databucket url>/api/bucket/users/12 -H "Authorization: Bearer $TOKEN"

Errors

Errors are returned with a message field describing the problem, e.g. {"message": "The tag 999 doesn't exist"} or, for an invalid field, {"message": "icon.svg: The icon contains a forbidden element: style"}. Server errors (500) name the request id, which is also in the X-Request-Id header, to find the details in the server log.

Status Meaning
400 The request is invalid, e.g. both sides of a rule are constants, a value that doesn't fit the type used in a rule, an invalid field
409 The data conflicts with other data
401 Missing, invalid or expired token; wrong user name or password
403 The user may not sign in to the project, or doesn't have the role required by the endpoint
404 The bucket doesn't exist or the user has no access to it
406 The request can't be done, e.g. an unknown tag, modifying or deleting without rules, a limit lower than 1 when reserving

Next steps

Clone this wiki locally