Skip to content

Records

import { Aside } from ‘@astrojs/starlight/components’;

All record methods require a collection to be selected first via .collection(). Every Ex method returns a PBResponse; the convenience variants return only the raw body String.

Fetch a single record by ID.

PBResponse getOneEx(
const char* recordId,
const char* expand = nullptr,
const char* fields = nullptr
);
ParameterTypeDescription
recordIdconst char*ID of the record. Must not be empty.
expandconst char*Comma-separated relation fields to expand, e.g. "author,tags". nullptr to skip.
fieldsconst char*Comma-separated fields to include in the response, e.g. "id,title". nullptr for all fields.

PocketBase endpoint: GET /api/collections/{collection}/records/{id}

PBResponse resp = pb.collection("posts").getOneEx(
"RECORD_ID",
"author", // expand the author relation
"id,title,body" // return only these fields
);
if (resp.ok) Serial.println(resp.body);

Fetch a paginated list of records. All parameters are optional — pass nullptr to use the server default.

PBResponse getListEx(
const char* page = nullptr,
const char* perPage = nullptr,
const char* sort = nullptr,
const char* filter = nullptr,
const char* skipTotal = nullptr,
const char* expand = nullptr,
const char* fields = nullptr
);
ParameterDefaultDescription
page1Page number (1-based).
perPage30Records per page (max 500).
sortSort expression. Prefix with - for DESC, e.g. "-created,id".
filterPocketBase filter expression, e.g. "active = true && views > 100".
skipTotalPass "1" to omit totalItems/totalPages for faster queries.
expandComma-separated relation fields to expand.
fieldsComma-separated fields to include in each record.

PocketBase endpoint: GET /api/collections/{collection}/records

// Page 1, newest 10, only active records
PBResponse resp = pb.collection("notes").getListEx(
"1", "10", "-created",
"active = true",
nullptr, nullptr, nullptr
);
// Fast query — skip total count
PBResponse fast = pb.collection("logs").getListEx(
"1", "50", "-created",
nullptr, "1", // skipTotal = "1"
nullptr, nullptr
);

Sort syntax

ExpressionResult
"created"Oldest first (ASC)
"-created"Newest first (DESC)
"-views,title"Most viewed, then alphabetical

Filter examples

active = true
active = true && views > 100
title ~ 'hello'
created >= '2024-01-01'

Create a new record.

PBResponse createEx(const String& requestBody);
ParameterTypeDescription
requestBodyStringJSON string of the fields to set.

PocketBase endpoint: POST /api/collections/{collection}/records

PBResponse resp = pb.collection("notes").createEx(
"{\"title\":\"Hello from ESP\",\"active\":true}"
);
if (resp.ok) Serial.println("New id: " + resp.body);

Partially update an existing record. Only the fields present in requestBody are changed — omitted fields retain their current values (PATCH semantics).

PBResponse updateEx(const char* recordId, const String& requestBody);
ParameterTypeDescription
recordIdconst char*ID of the record to update. Must not be empty.
requestBodyStringJSON string of fields to update.

PocketBase endpoint: PATCH /api/collections/{collection}/records/{id}

PBResponse resp = pb.collection("notes").updateEx(
"RECORD_ID",
"{\"title\":\"Updated title\"}"
);

Delete a record by ID.

PBResponse deleteRecordEx(const char* recordId);
ParameterTypeDescription
recordIdconst char*ID of the record to delete. Must not be empty.

A successful delete returns HTTP 204 with an empty body. PBResponse::ok is true and body is empty.

PocketBase endpoint: DELETE /api/collections/{collection}/records/{id}

PBResponse resp = pb.collection("notes").deleteRecordEx("RECORD_ID");
if (resp.ok) Serial.println("Deleted");

Wrappers around the Ex methods that return only the raw body String. Return an empty string on failure.

String getOne(const char* recordId,
const char* expand = nullptr,
const char* fields = nullptr);
String getList(const char* page = nullptr,
const char* perPage = nullptr,
const char* sort = nullptr,
const char* filter = nullptr,
const char* skipTotal = nullptr,
const char* expand = nullptr,
const char* fields = nullptr);
String create(const String& requestBody);
String update(const char* recordId, const String& requestBody);
String deleteRecord(const char* recordId);
// Quick read — no error handling needed
String body = pb.collection("notes").getOne("RECORD_ID");
Serial.println(body);
// Quick create — log and continue
pb.collection("events").create("{\"type\":\"boot\"}");