Public API
Relevant source files
The following files were used as context for generating this wiki page:
The Budibase Public API provides a simple and flexible way to interact with Budibase applications programmatically. It is designed to enable two primary use cases: using Budibase as a backend for other applications and facilitating interoperability between Budibase and other systems. This allows developers to extend Budibase's functionality and integrate it into a wider technology stack.
The API exposes endpoints for common data operations, allowing external services to create, read, update, and delete data within Budibase apps. Authentication is managed via API keys, ensuring secure access to application data.
Sources: README.md, docs/docs/public-api/readme.md
Architecture Overview
The Public API is a component of the packages/server module, which is a Koa application. Incoming requests to the public API endpoints are handled by a dedicated router that directs traffic to the appropriate controllers for processing.
This diagram illustrates the high-level flow of a request to the Public API.
API Routing
The entry point for all public API routes is defined in packages/server/src/api/routes/public/index.ts. This file initializes a Koa router and mounts sub-routers for different resources. The primary resource exposed is for table rows, which is handled by the rows controller.
// packages/server/src/api/routes/public/index.ts:7-13
import Router from "koa-router"
import rows from "./rows"
const router = new Router({
prefix: "/api/public/v1",
})
router.use(rows.routes())
The router is prefixed with /api/public/v1, establishing a versioned namespace for all public API endpoints.
Sources: packages/server/src/api/routes/public/index.ts:7-13
Authentication
To interact with the Public API, requests must be authenticated using an API key. The key, along with the App ID, must be included in the request headers.
| Header | Description | Required |
|---|---|---|
x-budibase-api-key | Your Budibase API key. | Yes |
x-budibase-app-id | The ID of the Budibase application you are targeting (e.g., app_dev_... or app_prod_...). | Yes |
These headers are specified in the OpenAPI definition as required parameters for API endpoints.
Sources: docs/docs/public-api/readme.md, packages/server/specs/openapi.json
Endpoints
The Public API primarily provides CRUD (Create, Read, Update, Delete) operations on table rows. These endpoints are defined in the rows controller.
Sources: packages/server/src/api/controllers/public/rows.ts
Rows Controller
The rows controller manages all data interactions for tables within a Budibase application.
The following diagram shows the sequence of a client searching for rows in a table via the API.
Main Row Operations
| Method | Path | Controller Function | Description |
|---|---|---|---|
POST | /tables/:tableId/rows/search | searchRows | Searches for rows in a specified table. Supports pagination, sorting, and filtering. |
GET | /tables/:tableId/rows/:rowId | getRow | Retrieves a single row by its ID. |
POST | /tables/:tableId/rows | saveRow | Creates a new row in a table. |
PATCH | /tables/:tableId/rows/:rowId | patchRow | Updates an existing row. |
DELETE | /tables/:tableId/rows/:rowId | deleteRow | Deletes a row from a table. |
Sources: packages/server/src/api/controllers/public/rows.ts, packages/server/specs/openapi.json
Search Rows (POST /tables/:tableId/rows/search)
This is the most flexible endpoint for retrieving data. It accepts a JSON body to specify query parameters.
Example Request Body:
{
"query": {
"string": {
"name": "John"
}
},
"sort": "name",
"sortOrder": "ascending",
"limit": 10,
"paginate": true
}
The controller logic for this endpoint is found in the searchRows function.
// packages/server/src/api/controllers/public/rows.ts:18-20
controller.post(
"/tables/:tableId/rows/search",
check,
validator(schemas.rows.search),
searchRows
)
Sources: packages/server/src/api/controllers/public/rows.ts:18-20, packages/server/specs/openapi.json
API Specification (OpenAPI)
Budibase provides an openapi.json file that formally defines the structure of the Public API. This specification follows the OpenAPI 3.0 standard and can be used to generate client libraries, documentation, or to configure tools like Postman.
The specification details all available paths, their required parameters, request bodies, and possible responses. For example, the path for creating a row is defined as follows:
// packages/server/specs/openapi.json
"/tables/{tableId}/rows": {
"post": {
"summary": "Create Row",
"description": "Create a new row in a table",
"operationId": "createRow",
"parameters": [
// ... header parameters like x-budibase-api-key
],
"requestBody": {
"description": "The row to create",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"responses": {
"200": {
"description": "Row created successfully"
}
}
}
}
Sources: packages/server/specs/openapi.json
Example Usage
The repository includes an example of a Next.js sales application that uses the Budibase Public API as its backend. This demonstrates a practical use case for consuming the API to build a full-stack application. The example configures the API key and app name in next.config.js and makes calls to the API routes.
This highlights the API's role in enabling Budibase to serve as a headless backend for custom frontends.
Sources: examples/nextjs-api-sales/README.md
Summary
The Budibase Public API is a powerful feature for extending the platform's capabilities. By providing standardized, secure, and versioned endpoints for data manipulation, it allows developers to integrate Budibase with external systems, use it as a backend for custom applications, and build complex workflows. The inclusion of an OpenAPI specification further enhances the developer experience by making the API easy to explore and consume.
Sources: README.md, docs/docs/public-api/readme.md