REST API

Request Examples

REST API request examples for all HTTP methods and how to parse responses.

This document explains the common request format for the Onttle REST API. It covers the required headers for all endpoints, request patterns per HTTP method, and response parsing.


Basic Request Format

Base URL: https://api.onttle.com/v1

Include the following headers in every request.

Header Value Required
Authorization Bearer {API_KEY} Always
Content-Type application/json POST, PUT requests

The API Key can also be sent in the X-Onttle-Key: {API_KEY} header instead of Authorization. See Authentication for details.

A Table's Contents are handled through the paths below. {table} is the Table's slug or ID, and {id} is the content's ID or slug. The examples in this document use a Table whose slug is posts.

Method Path Description
GET /{projectId}/tables/{table} List Contents
GET /{projectId}/tables/{table}/{id} Get one content item
POST /{projectId}/tables/{table} Create Contents
PUT /{projectId}/tables/{table}/{id} Update Contents (full replacement)
DELETE /{projectId}/tables/{table}/{id} Delete Contents
DELETE /{projectId}/tables/{table} Delete several Contents

There is no PATCH for partial updates.


GET Request — List

Retrieve a list of Contents. Only published Contents are returned.

curl

curl "https://api.onttle.com/v1/{projectId}/tables/posts?page=1&size=20" \
  -H "Authorization: Bearer $ONTTLE_API_KEY"

TypeScript

const res = await fetch(
  `https://api.onttle.com/v1/${projectId}/tables/posts?page=1&size=20`,
  {
    headers: {
      Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
    },
  },
)

if (!res.ok) throw new Error(`HTTP ${res.status}`)

const { list, pagination } = await res.json()

List Query Parameters

The list API supports the following query parameters.

Parameter Type Description
page number Page number (default: 1)
size number Items per page. An integer from 1 to 100 (default: 50)
sort string Sort conditions. A JSON array or the field:direction shorthand (default: created_at descending)
filter string Filter conditions array (JSON string). Can also be sent as filters
op string Filter combination operator (AND or OR, default: AND)
search string Search keyword, matched against text Columns, slug and SEO fields
language string Returns localized values as the value of one language. Can also be sent as lang or locale
fields string List of fields to return (comma-separated)
  • In sort, filter and fields, Columns are addressed by Column name. The available names differ per Table.
  • The JSON of sort and filter must be URL-encoded. URLSearchParams and curl's --data-urlencode encode it for you.
  • A value that cannot be applied, such as a Column name the Table does not have or a language the Project does not have, returns 400 invalidRequest.

sort

A JSON array of objects with the sort target in i and the direction (asc or desc) in o. Items are applied in array order.

[{ "i": "view_count", "o": "desc" }, { "i": "created_at", "o": "desc" }]
  • i is a Column name or one of created_at, updated_at, published_at, slug.
  • A shorthand is also accepted: sort=view_count:asc, or comma-separated for several: sort=view_count:desc,created_at:desc.
  • Without sort, the list is ordered by created_at descending (newest first).

filter

A JSON array of objects with i (target), w (operator) and v (value).

[
  { "i": "title", "w": "contains", "v": "onttle" },
  { "i": "view_count", "w": "greater_than_or_equal", "v": 100 }
]
  • i is a Column name or one of id, slug, created_at, updated_at, published_at.
  • Several conditions are combined with op=AND (default, all must match) or op=OR (any may match).

The operators (w) you can use depend on the target.

Target (i) Operators (w) Value (v)
id equals, not Content ID
slug equals, not, contains, not_contains, starts_with, ends_with, null, not_null String
created_at, updated_at, published_at is, is_not, before, after, between, not_between, null, not_null Date string. between takes [start, end]
TEXT, EMAIL, URL, COLOR Column equals, not, contains, not_contains, starts_with, ends_with, null, not_null String
EDITOR Column equals, not, contains, not_contains, starts_with, ends_with, null, not_null String (compared with the plain text of the body)
NUMBER Column equals, not, greater_than, greater_than_or_equal, less_than, less_than_or_equal, between, null, not_null Number. between takes [min, max]
DATE, TIMESTAMP Column is, is_not, before, after, between, not_between, null, not_null Date string. between takes [start, end]
BOOLEAN Column is true or false
CATEGORY Column has, not_has, empty, not_empty Category value ID, or an array of IDs
Column with the multiple option has, not_has, empty, not_empty The value to look for
  • null, not_null, empty and not_empty are used without v.
  • Date comparisons on created_at, updated_at and published_at work by day. is means that one day, before means earlier than that day, after means later than that day, and between includes both the start and end day.
  • When has on a CATEGORY Column receives several IDs, Contents that have any one of them are returned.
  • A localized (localization) TEXT Column is compared in the language given by language. Without language, the Project's primary language is used.

With search, only Contents whose text Columns, slug or SEO fields contain the keyword are returned. Combined with filter, Contents must match both. For search with scores and reranking, use BM25 Search or Embeddings Search.

language

language takes one of the language codes set on the Project. When given, the value of a localized Column is returned as a single string for that language instead of a { "ko": …, "en": … } object. Without it, the object is returned as is. See Response Format for response examples.

fields

fields takes the Column names to return, separated by commas. Besides Columns you can name slug, seo_title, seo_description, seo_image, created_at, updated_at and published_at. id and owner_member_id are always returned.

curl (combined parameters)

curl -G "https://api.onttle.com/v1/{projectId}/tables/posts" \
  -H "Authorization: Bearer $ONTTLE_API_KEY" \
  --data-urlencode 'page=1' \
  --data-urlencode 'size=20' \
  --data-urlencode 'sort=[{"i":"view_count","o":"desc"}]' \
  --data-urlencode 'filter=[{"i":"title","w":"contains","v":"onttle"}]' \
  --data-urlencode 'language=en' \
  --data-urlencode 'fields=title,slug,created_at'

TypeScript (URLSearchParams example)

const sort = [
  { i: 'view_count', o: 'desc' },
  { i: 'created_at', o: 'desc' },
]

const filter = [
  { i: 'slug', w: 'contains', v: 'guide' },
  { i: 'title', w: 'contains', v: 'onttle' },
]

const params = new URLSearchParams({
  page: '1',
  size: '20',
  fields: 'title,slug,created_at',
  sort: JSON.stringify(sort),
  filter: JSON.stringify(filter),
  op: 'AND',
  language: 'en',
})

const res = await fetch(
  `https://api.onttle.com/v1/${projectId}/tables/posts?${params.toString()}`,
  {
    headers: {
      Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
    },
  },
)

GET Request — Single Item

Retrieve a specific content item by ID or slug. The language and fields parameters work the same way as in the list API.

If the content does not exist, is not published, or has been deleted, 404 notFound is returned. A Table that does not exist also returns 404.

curl

curl "https://api.onttle.com/v1/{projectId}/tables/posts/{id}?language=en" \
  -H "Authorization: Bearer $ONTTLE_API_KEY"

TypeScript — with Next.js cache options

const res = await fetch(
  `https://api.onttle.com/v1/${projectId}/tables/posts/${id}`,
  {
    headers: {
      Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
    },
    next: { revalidate: 60 }, // ISR: revalidate every 60 seconds
  },
)

if (res.status === 404) return null
if (!res.ok) throw new Error(`HTTP ${res.status}`)

const contents = await res.json()

POST Request — Create

Create new Contents. A secret API Key (sk-proj_…) is required. A publishable key can write only when the Table's permission rule allows it.

The request body is a JSON object whose top-level keys are Column names. Do not wrap Column values in data. Besides Columns, the keys below can be sent.

Key Type Description
is_publish boolean true publishes the Contents. Omitted or false saves them as a draft
slug string Content slug. Stored only on Tables that use slugs
seo_title object | string SEO title, one text per language: { "ko": "…", "en": "…" }. Stored only on Tables that use SEO
seo_description object | string SEO description. Same shape as seo_title
seo_image string ID of the file to use as the SEO image. Stored only on Tables that use SEO
  • seo_title and seo_description are stored per Project language. A single string is stored as the text of the Project's primary language. Language keys the Project does not have are ignored.
  • A key that is neither a Column name nor one of the keys above (for example data or status) returns 400 invalidJsonInput (Unknown keys: …).
  • The owner of Contents cannot be set in the request body. Send the request with a member token and the server records that member as the owner, returned as owner_member_id in the response. owner_member_id in the body is an unknown key and returns 400.
  • Contents saved as a draft are not returned by the read APIs. Send is_publish: true to expose them through the API right away.
  • A FILE Column takes the ID of an uploaded file, a CATEGORY Column takes a category value ID, and a REFERENCE Column takes the ID of the referenced content.
  • slug must be unique within the Table, and cannot be in UUID format or a reserved word (id, slug, created_at, updated_at, published_at).

curl

curl -X POST "https://api.onttle.com/v1/{projectId}/tables/posts" \
  -H "Authorization: Bearer $ONTTLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "New Post",
    "view_count": 0,
    "slug": "new-post",
    "is_publish": true
  }'

TypeScript

const res = await fetch(
  `https://api.onttle.com/v1/${projectId}/tables/posts`,
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      title: 'New Post',
      view_count: 0,
      slug: 'new-post',
      is_publish: true,
    }),
  },
)

if (!res.ok) {
  // Error response: { type, title, message } — message is a string or an array of strings
  const error = await res.json()
  const message = Array.isArray(error.message)
    ? error.message.join(', ')
    : error.message
  throw new Error(message ?? `HTTP ${res.status}`)
}

const created = await res.json()

On success, the created Contents are returned in the single-item response format. Unlike the request, the response carries Column values inside a data object.


PUT Request — Update

Update existing Contents. The body format is the same as for POST.

Warning: PUT is a full replacement. The value of any Column you leave out of the body is not kept — it is cleared. Sending only some Columns erases the data of the others. Include the current value of every Column, including the ones you are not changing. There is no PATCH for partial updates.

  • required Columns must be sent on update as well. If one is missing, 400 invalidRequest is returned.
  • If is_publish is omitted, the publish state is not changed: published Contents stay published with the new values, and a draft stays a draft. Send true to publish the update.
  • slug, seo_title, seo_description and seo_image keep their existing values when omitted.
  • seo_title and seo_description are merged per language: only the languages you send change, the others keep their text, and a language sent as an empty string or null is cleared.
  • Read responses return FILE, CATEGORY and REFERENCE values as objects, but requests take IDs. Do not send a fetched data object back as is; convert these Columns to IDs first.
  • Locked Contents cannot be updated (400 contentsLocked).

curl

# Send the value of every Column of the posts Table
curl -X PUT "https://api.onttle.com/v1/{projectId}/tables/posts/{id}" \
  -H "Authorization: Bearer $ONTTLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Title",
    "body": "The existing body, sent again unchanged.",
    "view_count": 120,
    "is_publish": true
  }'

On success, the updated Contents are returned.


DELETE Request — Delete

Delete Contents. Locked Contents cannot be deleted (400 contentsLocked).

curl

curl -X DELETE "https://api.onttle.com/v1/{projectId}/tables/posts/{id}" \
  -H "Authorization: Bearer $ONTTLE_API_KEY"

TypeScript

const res = await fetch(
  `https://api.onttle.com/v1/${projectId}/tables/posts/${id}`,
  {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
    },
  },
)

if (res.status === 404) return // already deleted, or no such content
if (!res.ok) throw new Error(`HTTP ${res.status}`)

const deletedId: string = await res.json() // ID of the deleted content

To delete several items at once, send an ids array to the Table path. The response is the number of deleted items ({ "count": 2 }); locked Contents are skipped.

curl -X DELETE "https://api.onttle.com/v1/{projectId}/tables/posts" \
  -H "Authorization: Bearer $ONTTLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "ids": ["0c8f6c1e-5d1b-4f0a-9a3e-2b7d4e6f8a10", "7a1d2c3b-4e5f-4a6b-8c7d-9e0f1a2b3c4d"] }'

Environment Variable Management

A pattern for reading environment variables in Next.js.

// lib/onttle.ts
const API_BASE = 'https://api.onttle.com/v1'
const PROJECT_ID = process.env.ONTTLE_PROJECT_ID!
const API_KEY = process.env.ONTTLE_API_KEY!

export function onttleFetch(path: string, init?: RequestInit) {
  return fetch(`${API_BASE}/${PROJECT_ID}${path}`, {
    ...init,
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
      ...init?.headers,
    },
  })
}
// Usage
const res = await onttleFetch('/tables/posts?page=1&size=20')
const { list } = await res.json()

Next Steps

  • Pagination — Understand how to iterate through multiple pages of data.
  • Response Format — Understand the structure of list and single-item responses.
  • Error Codes — Check the type and status code of error responses.