# Pagination

![](/files/-Ma8jL3LksRITp3QDdNv)

## Pagination explained

Sometimes the data returned is just to long to display at once, such as product list, or branch list...etc. Displaying all this output data in one page will cause the app to load slow for the end users, so the pagination is the best option to control the output data to our needs.

### Page parameter

Certain routes, such as index listing may return an array of results.

By default, the API will return the results in batch. The `page` parameter may be used to increase the number of results per request.

To get the next batch of results, call the same route again with a page request parameter corresponding to the `next_page` and `total` property received in the last call on the `pagination` part of the response.

{% hint style="info" %}
&#x20;The returned `JSON` data will work with the `page` specified or no, but it's a good practice to use it, to make your app load faster and give your users best experience possible.
{% endhint %}

### Example

Notice the `URLOPT_POSTFIELDS => "{\"page\":5}",`

You could also use `null` to start fro page 1 and give next page as 2

```php
 <?php
 
 $curl = curl_init();

curl_setopt_array($curl, [
 CURLOPT_URL => "https://sandbox.mnasati.com/v1/orders",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "POST",
 CURLOPT_POSTFIELDS => "{\"page\":5}",
 CURLOPT_HTTPHEADER => [
   "Authorization-Jwt: Jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZW5kb3JfaWQiOiI0MyIsInVzZXJfaWQiOiI0MCIsInVzZXJfdHlwZSI6InZlbmRvciIsImVtYWlsIjoiemF6YUB1aWd0Yy5jb20iLCJpYXQiOjE2MjE0OTE0ODYsImV4cCI6MTYyNjY3NTQ4Nn0.Pa870uzsaRvFayG8S7oBlS_y66vCN0r4L_ab5A8SpqQ",
   "Content-Type: application/json"
 ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
 echo "cURL Error #:" . $err;
} else {
 echo $response;
}
```

Here is the response of the `page` parameter for pagination.

{% code title="JSON data returned" %}

```javascript
{
   "status":true,
   "total":6341,
   "next_page":6,
   "orders":[
      {
         "sale_id":"7049",
         "sale_code":"KNCZ-7049",
         "buyer_name":"dania",
         "buyer_email":"",
         "buyer_phone":"999999999",
         "buyer_phone_code":"974",
         "fund_number":"",
         "shipping":"30.000",
         "payment_type_id":"1",
         .....................
```

{% endcode %}

And if you were to enter an invalid (non existence page number) in your call, you would get the following response:

```javascript
{
   "status":true,
   "total":6341,
   "next_page":null,
   "orders":[
      
   ]
}
```


---

# 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.mnasati.com/pagination.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.
