ページネーション
API キーを取得一覧(GET /v1/posts、GET /v1/media)は、新しい順に 1 ページずつ返されます。limit でページサイズを 1〜100(デフォルトは 20)の範囲で指定します。
{
"data": [ … ],
"nextCursor": "WyIyMDI2LTEwLTI3VDE1OjExOjU5LjAxN1oiLCIx…"
}次のページを取得するには、nextCursor を cursor として渡します。nextCursor がなければ、最後に到達しています。
let cursor;
do {
const url = new URL('https://api.sofia-post.com/api/v1/posts');
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const page = await globalThis.fetch(url, { headers: { Authorization: `Bearer ${key}` } }).then((r) => r.json());
handle(page.data);
cursor = page.nextCursor;
} while (cursor);カーソルは不透明です。自分で作成したり変更したりしないでください。Sofia が返していないカーソルは 400 invalid_cursor で応答されます。