> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devinenterprise.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ページネーション

> Devin API 全体でのカーソルベースのページネーションの仕組み

Organization API および Enterprise API のすべてのリスト系エンドポイントでは、**カーソルベースのページネーション**を使用します。これにより、結果セットのサイズにかかわらず、一貫性があり効率的なページネーションが可能になります。

<div id="how-it-works">
  ## 仕組み
</div>

すべてのリストエンドポイントは、2 つのクエリパラメータを受け取ります。

| Parameter | Type    | Description                               |
| --------- | ------- | ----------------------------------------- |
| `first`   | integer | 1 ページあたりに返す項目数の上限（デフォルト値はエンドポイントごとに異なります） |
| `after`   | string  | 前のレスポンスで返された不透明なカーソル。最初のページでは省略します        |

<div id="response-format">
  ### レスポンス形式
</div>

リスト形式のレスポンスには、ページネーション用のメタデータが含まれます：

```json theme={null}
{
  "items": [...],
  "has_next_page": true,
  "end_cursor": "eyJsYXN0X2lkIjoiYWJjMTIzIn0=",
  "total": 142
}
```

| Field           | Description                                                                  |
| --------------- | ---------------------------------------------------------------------------- |
| `items`         | 現在のページの結果の配列                                                                 |
| `has_next_page` | 追加の結果がある場合は `true`                                                           |
| `end_cursor`    | 次のページを取得するために、これを `after` パラメータとして渡します。`has_next_page` が `false` の場合は `null` |
| `total`         | 一致するアイテムの総数（一部のエンドポイントではパフォーマンス上の理由で省略される場合があります）                            |

<div id="example-paginating-through-sessions">
  ## 例: セッションのページング
</div>

<div id="first-page">
  ### 最初のページ
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions?first=10" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="next-page">
  ### 次のページ
</div>

前のレスポンスの `end_cursor` の値を使用してください：

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions?first=10&after=eyJsYXN0X2lkIjoiYWJjMTIzIn0=" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="collecting-all-results">
  ### 全件の結果を取得する
</div>

```python theme={null}
import os
import requests

org_id = os.environ["DEVIN_ORG_ID"]
url = f"https://api.devin.ai/v3/organizations/{org_id}/sessions"
headers = {"Authorization": f"Bearer {os.environ['DEVIN_API_KEY']}"}
all_sessions = []
cursor = None

while True:
    params = {"first": 50}
    if cursor:
        params["after"] = cursor

    response = requests.get(url, headers=headers, params=params).json()
    all_sessions.extend(response["items"])

    if not response.get("has_next_page"):
        break
    cursor = response["end_cursor"]

print(f"Fetched {len(all_sessions)} sessions")
```

<div id="migrating-from-offset-based-pagination">
  ## オフセットベースのページネーションからの移行
</div>

API v1 または v2 から移行する場合は、`offset`/`limit` を `after`/`first` に置き換えてください。

```bash theme={null}
# 変更前 (v1/v2)
curl ".../v1/sessions?offset=50&limit=25"

# 変更後
curl ".../v3/organizations/{org_id}/sessions?first=25&after=CURSOR_FROM_PREVIOUS_PAGE"
```

カーソルベースのページネーションは、ページ間でアイテムが追加・削除されても影響を受けないため、オフセットベースのページネーションよりも信頼性が高くなります。
