API reference

Recipes

Syncing entries from an external system

TOKEN=ic_…   # Token with write permission
API=https://example.com/api/v1

curl -s -X POST "$API/collections/team/items" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"data": {"name": "Ada Lovelace", "rolle": "Engineering"}, "published": true}'

Uploading an image and assigning it to an entry

FILE_ID=$(curl -s -H "Authorization: Bearer $TOKEN" -F file=@ada.jpg "$API/files" | jq '.[0].id')

curl -s -X PUT "$API/collections/team/items/12" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "{\"data\": {\"foto\": $FILE_ID}}"

Loading a public collection in the browser via JavaScript

Requires a collection with public_api: true – no token needed. Public collections send Access-Control-Allow-Origin: *, so the request also works from another domain (e.g. a display board). Without cookies and without an Authorization header – cross-origin, you only get published entries:

const res = await fetch('https://example.org/api/v1/collections/faq/items')
const items = await res.json()
for (const it of items) console.log(it.data.frage, it.data.antwort)

Creating and publishing a page via the API

curl -s -X POST "$API/pages" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"parent_id": 1, "title": "Impressum", "slug": "impressum", "published": true,
       "html": "{% include \"header\" %}<main><h1>{{ page.title }}</h1></main>"}'

JavaScript client with session (like the admin app)

async function api(method, path, body) {
  const res = await fetch('/api/v1' + path, {
    method,
    credentials: 'same-origin',
    headers: { 'X-IC-CSRF': '1', ...(body ? { 'Content-Type': 'application/json' } : {}) },
    body: body ? JSON.stringify(body) : undefined,
  })
  if (res.status === 204) return null
  const data = await res.json()
  if (!res.ok) throw new Error(data.error)
  return data
}

await api('POST', '/auth/login', { username: 'admin', password: '…' })
const pages = await api('GET', '/pages')