# Pagination Helper

### 🛠 Pagination Helper (Agent Handling)

***

These helpers calculate the correct `skip`, and let your app specify the page without worrying about the URL details.

{% tabs %}
{% tab title="Python" %}

#### 🐍 Python Helper

```python
import requests

def fetch_conversations(agentid=None, page=1, results=20, metadatasearch=""):
    skip = (page - 1) * results
    base = "https://yourdomain.com/api/Chat/GetConversations"
    
    if agentid:
        url = f"{base}/{agentid}"
    else:
        url = base

    params = {
        "results": results,
        "skip": skip,
        "metadatasearch": metadatasearch,
    }

    response = requests.get(url, params=params)
    return response.json()
    
def alt_fetch_conversations(agentid=None, page=1, results=20, metadatasearch=""):
    # Demonstrates the alternative way of calling GetConversations using only path parameters
    # E.g. `/api/Chat/GetConversations/{agentid}/{results}/{skip}/{metadatasearch}`
    skip = (page - 1) * results
    base = "https://yourdomain.com/api/Chat/GetConversations"
    
    if agentid is not None and \
        page is not None and \
        results is not None and \
        metadatasearch:
        
        url = f"{base}/{agentid}/{results}/{skip}/{metadatsearch}"
        response = requests.get(url)
        return response.json()
   else:  # If not all params have valid value, use GET params instead of path ones
       return fetch_conversations(agentid, page, results, metadatasearch)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
async function fetchConversations({ agentId = null, page = 1, results = 20, metadatasearch = "" }) {
  const skip = (page - 1) * results;
  const baseUrl = "https://yourdomain.com/api/Chat/GetConversations";
  const url = new URL(agentId ? `${baseUrl}/${agentId}` : baseUrl);

  url.searchParams.set("results", results);
  url.searchParams.set("skip", skip);
  url.searchParams.set("metadatasearch", metadatasearch);

  const res = await fetch(url);
  return await res.json();
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://docs.aicrisk.com/api-overview/chat-apis/pagination-getconversation-s/pagination-helper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
