ページネーション
一覧エンドポイント(GET /emails、/domains、/api-keys、/webhooks、/audiences、/audiences/{id}/contacts、/broadcasts、/suppressions)は、1 つのカーソル方式を共有しています。
| パラメーター | 説明 |
|---|---|
limit |
1 ページあたりの件数。1 〜 100。既定値は 20 です。 |
after |
項目の id。それより古い項目のページ(次のページ)を返します。 |
before |
項目の id。それより新しい項目のページ(前のページ)を返します。 |
after と before はどちらか一方だけを使ってください。両方を指定すると 422 が返ります。結果は新しい順です。カーソルは項目の id(作成日時順に並ぶ UUIDv7)なので、新しい項目が追加されてもページは安定しています。
{ "object": "list", "has_more": true, "data": [ { "object": "email", "id": "0192e1c4-7a3c-7a02-8e10-6c0f9d7a2b31", "...": "..." }, { "object": "email", "id": "0192e1c4-7a3b-7c1e-9d2f-3b5a8e6f4c10", "...": "..." } ]}has_more は、ページを進めている方向に、さらにページがあるかどうかを示します。
すべてのページをたどる
Section titled “すべてのページをたどる”import { SpacePost } from "@spacepost/node";
const spacepost = new SpacePost();
let after: string | undefined;for (;;) { const { data, error } = await spacepost.emails.list({ limit: 100, after }); if (error) throw new Error(error.message); for (const email of data.data) console.log(email.id, email.last_event); if (!data.has_more) break; after = data.data[data.data.length - 1]!.id;}curl "https://api.spacepost.dev/emails?limit=100" -H "Authorization: Bearer $SPACEPOST_API_KEY"curl "https://api.spacepost.dev/emails?limit=100&after=0192e1c4-7a3b-7c1e-9d2f-3b5a8e6f4c10" -H "Authorization: Bearer $SPACEPOST_API_KEY"after = Nonewhile True: params = {"limit": 100, **({"after": after} if after else {})} page = requests.get("https://api.spacepost.dev/emails", headers=h, params=params).json() for email in page["data"]: print(email["id"], email["last_event"]) if not page["has_more"]: break after = page["data"][-1]["id"]- メールの一覧レスポンスには
htmlとtextが含まれません。本文が必要な場合は、メールを個別に取得してください。 - ドメインの一覧レスポンスには
recordsが含まれません。必要な場合は、ドメインを個別に取得してください。 - 不正な形式のカーソルは、
422 validation_error(“Invalid pagination cursor”)を返します。