docs · api
EN
Get started

Getting started

In under five minutes you'll make your first authenticated request and read a blog's published content. All you need is the blog's API key and an HTTP client.

Prerequisites

  • A blog created in DraftIn with at least one published post.
  • The blog's API key (the X-API-Key header). See Authentication.
  • An HTTP client: curl, the browser's fetch or Node 22+.

1. Keep your key safe

The API key grants read access to the blog's content. Keep it out of your source code — use an environment variable:

.env
# Never commit this file. Add ".env" to your .gitignore.
DRAFTIN_API_KEY=dra_xxxxxxxxxxxxxxxxxxxxxxxxxxx

2. Learn the base URL

All public endpoints live under the /public prefix from the production base https://api.draftin.io. A full path looks like this:

endpoint
https://api.draftin.io/public/posts

3. Make the first call

List the five most recent published posts. The key goes in the X-API-Key header; no other header is required for GET requests.

curl https://api.draftin.io/public/posts?limit=5 \
  -H "X-API-Key: $DRAFTIN_API_KEY"

A successful response (200 OK) is a { success, data } envelope with the array of Post objects in data:

200 OK
{
  "success": true,
  "data": [
    {
      "id": "clxxx101",
      "title": "My First Post",
      "subtitle": "Post subtitle",
      "slug": "my-first-post",
      "status": "PUBLISHED",
      "publishedAt": "2026-06-01T12:00:00.000Z",
      "content": "Post content in HTML or Markdown",
      "blogId": "clxxx789",
      "authorId": "clxxx123",
      "categories": [],
      "tags": []
    }
  ]
}

4. Handle missing authentication

If the key is wrong or missing, the API responds 401 Unauthorized. Always check res.ok (or the status) before consuming the body:

JavaScript
const res = await fetch("https://api.draftin.io/public/posts", {
  headers: { "X-API-Key": process.env.DRAFTIN_API_KEY },
});

switch (res.status) {
  case 200:
    return (await res.json()).data; // the payload comes in data
  case 401:
    throw new Error("Invalid or missing API key.");
  default:
    throw new Error(`Unexpected error: ${res.status}`);
}

Next steps