> For the complete documentation index, see [llms.txt](https://docs.autoenhance.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.autoenhance.ai/orders/managing-orders/listing-and-pagination.md).

# Listing and Pagination

The orders endpoint allows you to retrieve your orders with support for pagination using an offset. This enables you to efficiently navigate through large sets of orders. The endpoint supports `per_page` and `offset` query parameters. To retrieve orders with pagination, you must provide a valid API key.

### Retrieving a list of orders with a set per page limit

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

<pre class="language-javascript"><code class="lang-javascript"><strong>const apiKey = "YOUR_API_KEY";
</strong>const perPage = 16;

const getOrders = async (perPage, apiKey) => {
    const getOrdersResponse = await fetch(
      `https://api.autoenhance.ai/v3/orders?per_page=${perPage}`,
      { 
        method: "GET",
        headers:{
          "x-api-key": apiKey,  
        }
      }
    );

    const { orders, pagination } = await getOrdersResponse.json();
}
</code></pre>

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = "YOUR_API_KEY"
per_page = 16

def get_orders(per_page, api_key):
    url = f"https://api.autoenhance.ai/v3/orders?per_page={per_page}"
    headers = {
        "x-api-key": api_key
    }
    
    response = requests.get(url, headers=headers)
    response_data = response.json()
    
    orders = response_data.get('orders')
    pagination = response_data.get('pagination')
    
    return orders, pagination
```

{% endtab %}

{% tab title="PHP" %}

```php
$apiKey = "YOUR_API_KEY";
$perPage = 16;

function get_orders($perPage, $apiKey) {
    $url = "https://api.autoenhance.ai/v3/orders?per_page=$perPage";

    $options = array(
        'http' => array(
            'header'  => "Content-Type: application/json\r\n" .
                         "x-api-key: $apiKey",
            'method'  => 'GET'
        )
    );

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    if ($result === FALSE) {
        return 'Error fetching orders';
    }

    $orders_data = json_decode($result, true);
    return $orders_data;
}
```

{% endtab %}

{% tab title="cURL" %}

```
curl -X GET \
  'https://api.autoenhance.ai/v3/orders?per_page=16' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY'
```

{% endtab %}
{% endtabs %}

As you can see, the response returns an orders, and pagination object. The orders object contains the list of your orders, and pagination contains two values: **per\_page**, and **next\_offset**.

### Retrieving a paginated list of orders

If you want to load more orders with a pagination (next batch of orders without the initial orders that you've already fetched), you will need to use the next\_offset value in your next request.

{% hint style="info" %}
The value **next\_offset** is returned from in the object that is returned from retrieving a list of orders with a set per page limit
{% endhint %}

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

```javascript
const apiKey = "YOUR_API_KEY";
const pagination = { per_page:16, next_offset:"string" };

const loadMoreOrders = async (perPage, nextOffset, apiKey) => {
    const loadMoreOrdersResponse = await fetch(
      `https://api.autoenhance.ai/v3/orders?per_page=${perPage}&offset=${nextOffset}`,
      { 
        method: "GET",
        headers:{
          "x-api-key": apiKey,  
        }
      }
    );

    const { orders, pagination } = await getOrdersResponse.json();
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = "YOUR_API_KEY"
per_page = 16
next_offset = "string"

def load_more_orders(per_page, next_offset, api_key):
    url = f"https://api.autoenhance.ai/v3/orders?per_page={per_page}&offset={next_offset}"
    headers = {
        "x-api-key": api_key
    }
    
    response = requests.get(url, headers=headers)
    response_data = response.json()
    
    orders = response_data.get('orders')
    pagination = response_data.get('pagination')
    
    return orders, pagination
```

{% endtab %}

{% tab title="PHP" %}

<pre class="language-php"><code class="lang-php">$apiKey = "YOUR_API_KEY";
$perPage = 16;
$nextOffset = "<a data-footnote-ref href="#user-content-fn-1">string</a>";

function load_more_orders($perPage, $nextOffset, $apiKey) {
    $url = "https://api.autoenhance.ai/v3/orders?per_page=$perPage&#x26;offset=$nextOffset";

    $options = array(
        'http' => array(
            'header'  => "Content-Type: application/json\r\n" .
                         "x-api-key: $apiKey",
            'method'  => 'GET'
        )
    );

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    if ($result === FALSE) {
        return 'Error loading more orders';
    }

    $response_data = json_decode($result, true);
    return $response_data;
}
</code></pre>

{% endtab %}

{% tab title="cURL" %}

<pre><code>curl -X GET \
  'https://api.autoenhance.ai/v3/orders?per_page=16&#x26;offset=<a data-footnote-ref href="#user-content-fn-1">string</a>' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY'
</code></pre>

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Important note**\
The response will always return pagination object with values that will enable you to fetch next batch of orders if you still have more orders to fetch.
{% endhint %}

### Specification

{% openapi src="<https://api.autoenhance.ai/docs/openapi.spec>" path="/v3/orders/" method="get" %}
<https://api.autoenhance.ai/docs/openapi.spec>
{% endopenapi %}

[^1]: Offset returned from previous response where you've retrieved the orders.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.autoenhance.ai/orders/managing-orders/listing-and-pagination.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
