Blogs and docs
Resolve a post by its folder path, preview drafts, and manage tags and authors.
Blogs and docs are the same implementation over two separate trees. Everything
here applies to both - swap /api/blogs for /api/docs.
Posts live in folders, and the natural way to read one is by the path a visitor would use:
curl -G https://api.console.buildbase.app/api/blogs/path \
-H "Authorization: Bearer $BUILDBASE_TOKEN" \
--data-urlencode 'path=engineering/why-we-moved-off-cron'Before you start
Create folders and posts in the BuildBase console (publish a
post walks through it). Folders are usually made
there, but the API has them too, with the same org API token: POST /api/blogs/folders, PATCH /api/blogs/folders/:id and PATCH /api/blogs/folders/:id/archive (docs: /api/docs/folders). The token's role
needs create or update on blog (or doc) folders; the built-in content-reader
role is read-only.
Reading
| Method | Path | Purpose |
|---|---|---|
GET | /api/blogs | List posts, paginated, with the usual filter |
GET | /api/blogs/:id | One published post by id |
GET | /api/blogs/path | One post by folder path |
GET | /api/blogs/folders/tree | The folder tree |
The docs tree is at /api/docs/folders/tree. It sits under the folders routes,
so the token needs read access to folders, not just posts.
/folders/tree is what renders a sidebar - it returns the folder structure rather than
the posts themselves, so you can build navigation without pulling every post
body.
Paths
path is the folder path plus the post slug, joined with /:
engineering/why-we-moved-off-cron
└─ folder ─┘ └────── post slug ──────┘
The last segment is always the post; everything before it is folder structure. A post at the root is just its slug.
Previewing drafts
By default /path resolves only published posts. draftPreview=true switches
it to unpublished posts only - it does not add drafts to the published set:
curl -G https://api.console.buildbase.app/api/blogs/path \
-H "Authorization: Bearer $BUILDBASE_TOKEN" \
--data-urlencode 'path=engineering/upcoming-post' \
--data-urlencode 'draftPreview=true'Because the flag swaps one set for the other, a published post returns 404
with draftPreview=true set. A preview route that should show whatever exists
has to try the published read first and fall back to the draft one.
A read by id follows the same rule for an API token. GET /api/blogs/:id
returns a published post, and a draft's id answers 404, the same answer as an
id that does not exist; add draftPreview=true to read the draft (and, as with
/path, only a draft). So a site that routes by id never serves a draft to a
visitor who has its id. A console session is the editor and reads either.
curl -G https://api.console.buildbase.app/api/blogs/66f1a2b3c4d5e6f7a8b9c0d1 \
-H "Authorization: Bearer $BUILDBASE_TOKEN" \
--data-urlencode 'draftPreview=true'The server SDK's blogs.get(id) and docs.get(id) send no flag, so they return
published posts only and null for a draft.
Wire this to a preview route your editors can reach, and leave it off in the path your public site renders. Since the endpoint needs a token either way, "leaving it off" means your backend decides - a visitor cannot set it themselves.
Tags and authors
Both are managed with dedicated endpoints rather than through the post body, so a retag does not rewrite the content:
| Method | Path | Purpose |
|---|---|---|
PATCH | /api/blogs/:id/tags | Replace the post's tags |
PATCH | /api/blogs/:id/authors | Replace the post's authors |
Both replace rather than append. Read the current list, add to it, and send the whole array back.
Writing
| Method | Path | Purpose |
|---|---|---|
POST | /api/blogs | Create a post |
PATCH | /api/blogs/:id | Update a post |
DELETE | /api/blogs/:id | Delete a post |
The console is the expected authoring surface. The write endpoints are for migrations and syncing from another system - importing an existing blog, for instance.
Rendering on a public site
These endpoints need a token, so the browser never calls them. Two workable shapes:
- Build time. Fetch posts during your site build and render static pages. Fastest, and the token stays in CI. Nothing rebuilds on its own: start a deploy hook from the console's banner, which counts changed blog posts, or with Deploy under Settings > Deploy hooks. To rebuild on every change, call the hook from a content webhook.
- Server-side. Fetch in a server component or route handler, cache the result, and serve HTML. Use this when editors need changes live without a rebuild.
Either way the token stays server-side. See the admin API for token handling.
Next Steps
- Content overview - the other content types.
- Assets - images embedded in posts.
- Deploy hooks - rebuild a static site after posts change.