> For the complete documentation index, see [llms.txt](https://docs-embed.anyflow.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-embed.anyflow.jp/solution-editor/logic/pagination.md).

# ページネーション

ページネーションとは、大量のデータを複数のページに分割して取得ができる仕組みです。

SaaSごとにページングのサイズが異なったり、ページネーションの設定方法が異なります。\
そのため、各SaaSのAPIドキュメントを確認しながらページネーションを構築してください。

今回は**SlackBotでユーザー一覧を取得する際にページネーションで取得する方法**をご紹介します。200件ずつAPIでユーザーを取得し、1つのデータに格納していく使い方をご紹介します。

{% hint style="info" %}

#### SlackのAPIドキュメント

詳細は下記を参照してください。\
<https://docs.slack.dev/reference/methods/users.list/>
{% endhint %}

今回作成するページネーションの流れは下記の通りです。

<figure><img src="/files/dMb8sHg2jNS1NpC0soVR" alt=""><figcaption><p>✳️Anyflow Embedではfor文しか扱えない為、ループ回数の定義が必要です。</p></figcaption></figure>

ソリューションの詳細な作り方は下記をご確認ください。

{% hint style="success" %}

### 使用するアクションやロジックについて

詳細については下記を参照してください。

[変数について](https://docs-embed.anyflow.jp/solution-editor/actions/data-transform/variable)

[リストについて](https://docs-embed.anyflow.jp/solution-editor/actions/data-transform/list)

[繰り返しについて](https://docs-embed.anyflow.jp/solution-editor/logic/loop)
{% endhint %}

### 変数を作成する

変数アクションを追加します。

* \[Formulaで変数を作成]を選択します。
  * 変数定義：手動追加します。追加する定義は下記の通りです。
    * 名前\[next cursor]、型\[String]で、追加します。
  * 変数のオブジェクト：入力をFormulaに変更し、\[None]と入力します。

<figure><img src="/files/WBimS4nJ3n5u64Vv5vz5" alt="" width="375"><figcaption></figcaption></figure>

もう1つ変数アクションを追加します。

* \[Formulaで変数を作成]を選択します。
  * 変数定義：JSONまたは手動で追加できます。

{% tabs %}
{% tab title="{}JSONで追加" %}
JSONを入力するモーダルが表示されるので、以下のJSONをコピーして貼り付けます。

```
{  
  "user_list": [  
    {  
      "user": {}  
    }  
  ]  
}
```

{% endtab %}

{% tab title="手動追加" %}
手動追加追加する定義は下記の通りです。

* 名前\[user\_list]、型\[Array]で、任意項目にするにチェックを入れて追加します。

* 名前\[user]、型\[Object]で、任意項目にするにチェックを入れて追加します。

* userをuser\_listの配下に設定します。
  {% endtab %}
  {% endtabs %}

* 変数のオブジェクト：入力をFormulaに変更し、\[]と入力します。

<figure><img src="/files/BsBCqPKEnIhq95pdajSn" alt="" width="563"><figcaption></figcaption></figure>

変数を作成できたら、\[ユーザー一覧を取得]のステップを修正します。

* 取得件数：200と入力します。
* カーソル：変数の\[next cursor]に変更します。

<figure><img src="/files/sUk9jiLUficd2ijgaiWW" alt="" width="563"><figcaption></figcaption></figure>

### リストを作成する

次にリストを作成します。

* リストのアクションを追加します。
  * リストを作成を選択します。
    * サイズ：任意のサイズを設定します。今回は\[1000]とします。

<figure><img src="/files/pCUbJzLaVtnW2V6z6D4C" alt="" width="563"><figcaption></figcaption></figure>

### 繰り返しを設定する

次に繰り返しを設定します。繰り返しアクションを設定しないとリストを受け取ることができません。

* \[+]ボタンをクリックし、\[繰り返し]ステップを選択します。
  * 繰り返すリスト：変数の\[リスト]を選択します。
  * 繰り返しモード：\[アイテムごとに繰り返す]を選択します。

<figure><img src="/files/Zspc7EY5jwK9nm8RiiN6" alt="" width="563"><figcaption></figcaption></figure>

### 繰り返しにユーザー一覧取得を配置する

繰り返しステップの中にユーザー一覧を取得のステップを移動させます。

次に繰り返しユーザー一覧を取得するために変数の更新を2つ設定します。

1つ目の変数の更新

* ステップを追加しアクションから変数を選択します。
  * 変数を更新を選択します。
    * 変数選択：\[next cursor]を選択します。
    * オブジェクト：変数の\[NextCursor]を選択します。

<figure><img src="/files/L3LAvyR8vPBWXwiyzkaB" alt="" width="563"><figcaption></figcaption></figure>

2つ目の変数の更新

* ステップを追加しアクションから変数を選択します。
  * 変数を更新を選択します。
    * 変数選択：変数の\[user\_list]を選択します。
    * オブジェクト：変数を使用します。入力をFormulaに変更し、下記のように入力します。

```
[list(user_list | Step4)] + [(Members | Step7)]
```

<figure><img src="/files/3nZj1VeaP7IKynkYeR8q" alt="" width="563"><figcaption></figcaption></figure>

### 取得するページがなくなったら終了するステップを追加する

リストで設定したページよりも件数が少なかった場合に、取得を終了するステップを追加します。

* ステップで\[if]を選択します。
  * データ：変数にある\[NextCursor]を選択し、状態は\[空である]を選択します。
* 次のYes側にBreakのステップを追加します。

<figure><img src="/files/og3FfWj9C0VIfiUNR5Jr" alt="" width="563"><figcaption></figcaption></figure>

### レスポンスの設定を修正する

リストでユーザー一覧を取得した場合、レスポンスペイロードが変わるため、設定を修正します。

* レスポンス名を\[user\_list]に変更します。
  * リストソース：変数の\[user\_list]を選択します。
  * id：変数を使用します。入力をFormulaに変更し、下記のように入力します。

```
[i番目のuser | Step4]["id"]
```

<figure><img src="/files/qag6ixCcwiYv7rIlpdsz" alt="" width="563"><figcaption></figcaption></figure>

以上で設定は終了です。テストして成功するか確認してください。

この設定により、ページネーションによりデータを取得することができました。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-embed.anyflow.jp/solution-editor/logic/pagination.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
