Bear docs

API

Bear has a small API for managing your posts, blog settings, and media. It's available on upgraded blogs.

Getting started

Head to your dashboard → Settings → API and generate a key. Each key works for one blog, and you can regenerate or revoke it there whenever you like.

Your API lives at https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/ (use your Bear subdomain here, even if you have a custom domain). Send your key with every request:

Authorization: Bearer YOUR-API-KEY

Request bodies are JSON, so include Content-Type: application/json when creating or updating. File uploads are the one exception.

Keep your key private. Anyone who has it can edit your blog.

Posts

A post's uid never changes, even if its slug does.

Fields

Responses also include uid, url, and last_modified. Dates come back in UTC.

Drafts also include a token. Add ?token=TOKEN to the url for a preview link anyone can open.

Listing

Lists come back 20 at a time, newest first, without content (fetch a single post for that). You get posts, count, page, page_size, and next_page, which is null on the last page.

Blog

Fields

Responses also include last_modified.

Media

Uploading

Uploads are multipart/form-data instead of JSON: one file per request, in a field called file. The supported file types and the 10 MB size limit are the same as the media page in your dashboard. An upload has to finish sending within about 20 seconds, so on a slow connection keep files smaller.

Images are shrunk to 1200px wide and converted to WebP, just like in the dashboard (GIFs and SVGs are left alone). Add a raw field set to true to keep the original size and format.

File names get tidied up, and duplicates get a suffix, so use the url that comes back.

Fields

Responses include id, url, name, type, tags, and created_at. Tags are the ones you've set in the dashboard.

Listing

Lists come back 100 at a time, newest first. You get media, count, page, page_size, and next_page, which is null on the last page.

Examples

# List drafts
curl 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/post/?status=draft' \
  -H 'Authorization: Bearer YOUR-API-KEY'

# Create a draft
curl -X POST 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/post/' \
  -H 'Authorization: Bearer YOUR-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '{"title":"Hello from the API","content":"A **Markdown** draft.","tags":["api"]}'

# Publish it
curl -X PATCH 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/post/UID/' \
  -H 'Authorization: Bearer YOUR-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '{"publish":true}'

# Update the home page
curl -X PATCH 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/blog/' \
  -H 'Authorization: Bearer YOUR-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '{"content":"Welcome to my blog."}'

# Upload an image
curl -X POST 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/media/' \
  -H 'Authorization: Bearer YOUR-API-KEY' \
  -F 'file=@photo.jpg'

# Delete a post
curl -X DELETE 'https://bearblog.dev/YOUR-SUBDOMAIN/api/v1/post/UID/' \
  -H 'Authorization: Bearer YOUR-API-KEY'

Errors and limits

When something goes wrong you get a message like {"error":"title is required"}, and nothing is saved.