Help center

API and webhooks

Load your articles into your own site, and rebuild when one changes.

JoshUpdated 4 min read

How it works

When a blog publishes through the API, your site reads its published articles from ByDefault and renders them itself. Open Publishing, pick the blog and choose API as its method. Its API page gives you a key, the endpoint, and a place for a webhook URL. We call that URL every time an article is published, updated or unpublished.

The API serves each article as it was when you last published it. Edits in the editor stay private until you publish again.

Authentication

Send the key from the blog's API page as a bearer token:

HTTP

Each blog has its own key, and the key decides which blog's articles you get. Keep it on your server, for example as BYDEFAULT_API_KEY: anyone with it can read your published articles. Make a new key on the API page and the old one stops working at once.

List articles

GET /api/v1/articles returns your live articles, newest first, up to 100 per page. Page through them with limit (1 to 100) and offset. hasMore tells you whether another page follows.

Terminal
Response

Get one article

GET /api/v1/articles/:slug returns { "article": … }, or a 404 when no live article has that slug.

Response

Every image, in the body and in the authors' photos, is on cdn.bydefault.so. That's the one host to allow, in next/image or in a content security policy's img-src.

Webhooks

Add a URL under Webhooks on the API page and we POST to it whenever an article changes, so your site can rebuild or revalidate that page. Send test sends one right away with your newest article.

Request body

Every request carries three headers: X-ByDefault-Event, X-ByDefault-Delivery (one id per attempt) and X-ByDefault-Signature.

Answer with any 2xx within 10 seconds. If your site answers with anything else, or doesn't answer, we try again up to 3 times. Every attempt shows on the API page with what your site answered.

Verify a webhook

The signature is sha256= followed by the HMAC-SHA256 of the raw body, keyed with your API key. Check it before you trust the body:

app/api/revalidate/route.ts

Troubleshooting

I get a 401

The key is missing or wrong. Send it as Authorization: Bearer <key>, and check that it's the current key: making a new one stops the old one.

I get a 400

limit must be a whole number from 1 to 100, and offset a whole number from 0.

My site still shows the old version

The API serves what you last published. Publish the article again, then check the API page to see whether the webhook reached your site.

Webhook deliveries fail

The API page shows the status your site answered with on every attempt. Anything but a 2xx within 10 seconds counts as a failure, and so does a signature check that uses an old key.

Did this answer your question?

Turn AI search into your most profitable sales channel.