Filter, sort, and paginate
You can filter a list of entries by conditions, sort it in any order, and read it a few entries at a time. You use four parameters that you add to the list URL.
| Parameter | What it does | Default |
|---|---|---|
where |
Filters by conditions | No filter |
order |
Sorts | Newest published first (-sys.publishedAt) |
limit |
The number returned at a time. 0–100 | 20 |
offset |
The number skipped from the start | 0 |
These four work only for lists. If you add them to a URL that reads one entry or a single, you get 400.
Before you begin
Section titled “Before you begin”- An API key with the [読み取り](Read) permission. To issue one, see Create API keys and set permissions
- For how to read a list, see Read entries
In the examples below, replace <hostname> with the hostname of your environment and <API key> with your API key. The examples use the content type ID “posts” and the field ID “title”.
Filter (where)
Section titled “Filter (where)”In where, write an expression similar to an SQL WHERE clause. The expression contains spaces and symbols, so encode it when you put it in a URL. With curl, use --data-urlencode.
Filter to entries whose title contains “Rust”.
curl -G https://<hostname>.hakocms.net/api/v1/content/posts \ -H "Authorization: Bearer <API key>" \ --data-urlencode 'where=title contains "Rust"'Only matching entries are in items, and total is the number of matches.
In JavaScript, URLSearchParams does the encoding.
const params = new URLSearchParams({ where: 'title contains "Rust" and sys.publishedAt >= "2026-10-01"',});const res = await fetch( `https://<hostname>.hakocms.net/api/v1/content/posts?${params}`, { headers: { Authorization: "Bearer <API key>" } },);const { items, total } = await res.json();Expression syntax
Section titled “Expression syntax”| What you want | How to write it |
|---|---|
| Equal, not equal | category = "tech", category != "tech" |
| Greater or less | price < 1000, price <= 1000, price > 0, price >= 0 |
| Date and time | sys.publishedAt >= "2026-10-01", eventAt < "2026-10-08T09:00:00+09:00" |
| Contains, does not contain | title contains "Rust", title not contains "Rust" |
| Starts with | title startsWith "Rust" |
| Matches any, matches none | sys.id in ("a", "b"), category not in ("pr", "ad") |
| Has a value, has no value | eyecatch exists, eyecatch not exists |
| Combine | and, or, not, parentheses ( ) |
Here is an example that combines conditions.
category = "tech" and (title contains "Rust" or title contains "Go")- Enclose strings and dates in
"…"or'…'. Write quotes inside as\"\', and\as\\ - Do not enclose numbers,
true, orfalse - Write dates and times in RFC 3339, or as a date only. A date only means 0:00 (UTC) on that day. Comparisons are made in UTC
- Keywords such as
andornotcan be uppercase or lowercase notbinds first, thenand, thenor(the same as SQL)containsis a partial match.%and_have no special meaning- When you negate with
!=,not contains,not in, ornot, entries with no value also match
When you embed words that users typed into an expression, add \ before " and \, and then enclose them. If you embed them as is, a " in the words stops the expression from being read correctly.
const quote = (s) => `"${s.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;const where = `title contains ${quote(keyword)}`;Operators by field type
Section titled “Operators by field type”| Target | Operators you can use |
|---|---|
sys.id |
= != contains not contains startsWith in not in |
sys.createdAt sys.updatedAt sys.publishedAt sys.firstPublishedAt |
= != < <= > >= startsWith in not in |
| Text, text area | = != contains not contains startsWith in not in exists |
| Number | = != < <= > >= in not in exists |
| Date and time | = != < <= > >= startsWith in not in exists |
| Boolean | = != in not in. No value is compared as false |
| Reference | = != in not in exists on the referenced entry ID |
| Multiple references, select | = != contains not contains in not in exists. = means “has that value as an element” |
| Image, file, rich text, custom | exists |
| Multiple images, repeater | exists (whether it is not empty) |
You cannot filter by fields of referenced entries (such as author.name = "Kohei") yet. Filter by the referenced entry ID instead (author = "kohei").
Expression size
Section titled “Expression size”One expression can have up to 30 conditions, up to 5 levels of nested parentheses and not, up to 2000 characters, and up to 100 values in in. The whole URL can be up to 8 KB. If it is longer, you get 414.
Sort (order)
Section titled “Sort (order)”In order, write what to sort by. Put - at the start to sort from largest (newest). Separate with commas to sort entries that are equal on one key by the next key.
Sort newest published first, and by title when equal.
curl -G https://<hostname>.hakocms.net/api/v1/content/posts \ -H "Authorization: Bearer <API key>" \ --data-urlencode "order=-sys.publishedAt,title"- You can sort by
sys.id,sys.createdAt,sys.updatedAt,sys.publishedAt,sys.firstPublishedAt, and fields of type text, text area, date and time, and number - Strings are compared in byte order, numbers by value, and dates and times in time order
- Entries with no value come last in either direction
- Entries that are equal on all keys are sorted newest created first
Paginate (limit and offset)
Section titled “Paginate (limit and offset)”limit sets the number returned at a time, and offset sets the number skipped from the start. Read page 3 (entries 21–30) with 10 entries per page.
curl -G https://<hostname>.hakocms.net/api/v1/content/posts \ -H "Authorization: Bearer <API key>" \ -d limit=10 \ -d offset=20You get a response like this (the contents of items are omitted):
{ "items": [], "total": 42, "limit": 10, "offset": 20 }total is the number of all matches, before limit and offset divide it. The total number of pages is total divided by limit, rounded up.
To read all entries in order, increase offset by limit and repeat until you reach total. Set order so that the order does not change.
const base = "https://<hostname>.hakocms.net/api/v1/content/posts";const headers = { Authorization: "Bearer <API key>" };const all = [];for (let offset = 0; ; offset += 100) { const params = new URLSearchParams({ order: "sys.createdAt", limit: "100", offset: String(offset), }); const res = await fetch(`${base}?${params}`, { headers }); const { items, total } = await res.json(); all.push(...items); if (items.length === 0 || all.length >= total) break;}console.log(all.length);One response can be up to 5 MB. If it is larger, you get 400. In that case, make limit smaller, or reduce the returned fields with select (Read entries).
Check the result
Section titled “Check the result”If the returned total is the same as the number of entries you count with the same conditions in the admin, the filter works.
If the expression cannot be read, or you use an operator that the field does not support, you get 400, and message shows the reason. For an expression error, it also shows the character position.
| Expression | message |
|---|---|
title like "x" |
where: expected an operator (=, !=, <, <=, >, >=, contains, startsWith, in, exists) at character 7, found "like" |
nope = "x" |
where: unknown field "nope" |
title < "a" |
where: lt (<) cannot be used with the text field "title" |
price = "abc" |
where: "abc" is not a number ("price") |
title = 1 |
where: 1 is not a string; put it in quotes ("title") |