クエリ(絞り込み・並べ替え・項目・参照の深さ)
クエリの一覧
/content/<種類のキー> の
| クエリ | 例 | 働き |
|---|---|---|
limit |
limit=10 |
1 回に |
offset |
offset=20 |
先頭から |
order |
order=-updatedAt |
並べ替える- で |
filter[項目] |
filter[audience][in]=developer,admin |
絞り込み。 |
fields |
fields=title,slug |
返す項目を |
depth |
depth=0 |
参照先を |
ID やorder やfilter を/types では、draft とref は
URL の[ と] は、-g(--globoff)をURLSearchParams に
curl -g "https://api.kumidana.com/v1/docs/content/docs?filter[audience]=developer&limit=5" \
-H "Authorization: Bearer kmd_pub_xxxx"const params = new URLSearchParams({
'filter[audience]': 'developer',
limit: '5',
});
const res = await fetch(`${BASE}/content/docs?${params}`, { headers });件数とページ送り
limit は
offset はtotal はoffset + limit < total で
offset でid でtotal を
async function fetchAll(path: string): Promise<unknown[]> {
const all: unknown[] = [];
for (let offset = 0; ; offset += 100) {
const res = await fetch(`${BASE}${path}?limit=100&offset=${offset}`, { headers });
const page = await res.json();
all.push(...page.items);
if (offset + page.limit >= page.total) return all;
}
}並べ替える
order に- を
curl "https://api.kumidana.com/v1/docs/content/docs?order=position&limit=50" \
-H "Authorization: Bearer kmd_pub_xxxx"使える
publishedAt(公開日時。未設定なら 更新日時で 代用)と updatedAt(更新日時)- 種類の
定義で indexed: trueを付けた 項目。 uniqueの項目と、 slugFieldの項目も、 自動で 使えます
数値の
order をsort がsort に{ "field": "position", "order": "asc" })がmanual ならorder をmanual よりもorder が
indexed でない
{
"error": {
"code": "bad_request",
"message": "並べ替えに使えない項目です(indexed にしてください): summary"
}
}直すには、indexed: true を
絞り込む
絞り込みはfilter[項目]=値 のfilter[項目][演算子]=値 とeq です。
| 演算子 | 意味 | 例 |
|---|---|---|
eq |
値と |
filter[slug][eq]=entries |
ne |
値と |
filter[audience][ne]=admin |
in |
いずれかと |
filter[audience][in]=editor,developer |
lt |
より |
filter[position][lt]=30 |
lte |
以下 | filter[position][lte]=30 |
gt |
より |
filter[position][gt]=10 |
gte |
以上 | filter[position][gte]=10 |
演算子はfilter[position][GTE] のように
複数の
# 開発者向けで、並び順が 10 以上 40 未満のドキュメント
curl -g "https://api.kumidana.com/v1/docs/content/docs?filter[audience]=developer&filter[position][gte]=10&filter[position][lt]=40&order=position" \
-H "Authorization: Bearer kmd_pub_xxxx"参照のfilter[category][slug] のようなGET /content/<参照先の種類>/<スラッグ> のid をindexed が
つまり、filter に
// 1 回目: スラッグ → ID(参照先の種類 categories、スラッグ drinks)
const cat = await (await fetch(`${BASE}/content/categories/drinks`, { headers })).json();
// 2 回目: ID で絞る
const params = new URLSearchParams({ 'filter[category]': cat.id });
const { items } = await (await fetch(`${BASE}/content/products?${params}`, { headers })).json();参照先のGET /content/categories?limit=100 でentry.published で
const API_SECTION = '01a2229a-2299-7521-8d1d-3a714ea9df73'; // 章「コンテンツ API」
const params = new URLSearchParams({ 'filter[section]': API_SECTION, order: 'position' });
const { items } = await (await fetch(`${BASE}/content/docs?${params}`, { headers })).json();値の扱い
- 項目の
値が 配列 (複数選択の select や、 複数の reference)の ときは、 要素の どれかが 条件に 合えば合致です。 filter[audience]=developerは、audienceが[editor, developer]のエントリーにも 合います。 neは、その 値を 持たない ものすべてに 合致します。 項目が 空の エントリーも 含まれます。 numberの項目に 数値でない 値を 渡すと 400 です。 inに書ける 値は 50 個までです。 空の 要素は 取り除かれますが、 前後の 空白は 取り除かれないので、 a, bの2 つ目は b(空白つき)と して 比べます。 publishedAtとupdatedAtは、indexedを付けなくても 絞り込めます。 使える 演算子と 値の 書き方は、 次の 節に あります。
型ごとの値の書き方
number 以外のlt やgt はnumber の
| 型 | 保存される |
書き方の |
|---|---|---|
number |
数値 | filter[price][gte]=500。 |
boolean |
true かfalse の |
filter[featured]=true。1 やTrue は |
date |
2026-12-01 の |
filter[day][gte]=2026-12-01。 |
datetime |
UTC の2026-12-01T00:00:00Z の |
filter[startsAt][lt]=2026-12-01T00:00:00Z。Z で |
select |
選択肢の |
filter[status]=open。 |
text、slug、email、url、reference |
入れたreference は |
そのまま |
datetime は、Z で+09:00 のようなDate からtoISOString() の.000Z に.000 をnew Date().toISOString().replace(/\.\d{3}Z$/, 'Z') のようにします。2026-12-01T09:00Z)や、eq がlt とgt の
複数選択のselect やreference は、eq、in、lt などは、ne は、filter[tags][ne]=a は、a をtags が
publishedAt とupdatedAt 以外のindexed がindexed がtext、number、boolean、date、datetime、select、slug、reference、email、url です。
公開日時・更新日時で絞り込む
publishedAt(公開日時)とupdatedAt(更新日時)は、lt、lte、gt、gte で2026-12-01T00:00:00Z のように2026-12-01)でも+09:00 のように+ は%2B にZ でeq、ne、in は
publishedAt がupdatedAt の
# 今より前に公開日時が来ているものだけ(公開予約)
curl -g "https://api.kumidana.com/v1/docs/content/news?filter[publishedAt][lte]=2026-12-01T00:00:00Z&order=-publishedAt" \
-H "Authorization: Bearer kmd_pub_xxxx"現在時刻をpublishedAt を
絞り込みのエラー
| 状況 | メッセージ |
|---|---|
indexed でない |
絞り込みに<項目> |
| 演算子が |
未対応の<演算子> |
in が |
in の |
number の |
数値の<項目> |
publishedAt・updatedAt にlt、lte、gt、gte 以外の |
<項目> の<演算子> |
publishedAt・updatedAt の |
<項目> には |
ステータスは<項目> と<演算子> には、
返す項目を選ぶ
fields にdata の
curl "https://api.kumidana.com/v1/docs/content/docs?fields=title,slug,summary&limit=50" \
-H "Authorization: Bearer kmd_pub_xxxx"id、type、slug、publishedAt、updatedAt はfields= のようにfields をid、slug だけがfields=_)をdata がfields とdepth は、GET /content/<種類のキー> でfields の
参照を展開する
depth は、
| depth | 参照先の |
|---|---|
| 0 | id、type、slug だけ |
| 1 |
参照先のdata つき。id、type、slug だけ |
| 2 | 参照先の、data まで |
範囲の
curl "https://api.kumidana.com/v1/docs/content/docs/entries?depth=0" \
-H "Authorization: Bearer kmd_pub_xxxx"参照先がnull、