# Pagination

**URL:** <https://forum.api.combocurve.com/t/pagination/33>\
**Category:** Documentation\
**Tags:** guide\
**Created:** [December 6, 2021, 4:55am UTC](https://forum.api.combocurve.com/t/pagination/33 "2021-12-06T04:55:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maikel.ruiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/maikel.ruiz/32/101_2.png) [@maikel.ruiz](https://forum.api.combocurve.com/u/maikel.ruiz)\
**Post date:** [December 6, 2021, 4:55am UTC](https://forum.api.combocurve.com/t/pagination/33/1 "2021-12-06T04:55:03Z")

</div>

TODO: Content for this topic coming soon.

---

<div class="post-metadata">

**Author:** ![maikel.ruiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/maikel.ruiz/32/101_2.png) [@maikel.ruiz](https://forum.api.combocurve.com/u/maikel.ruiz)\
**Post date:** [December 29, 2021, 7:47pm UTC](https://forum.api.combocurve.com/t/pagination/33/2 "2021-12-29T19:47:57Z")

</div>

Came up on this question: [?take=all Paramater](https://forum.api.combocurve.com/t/take-all-paramater/65)

---

<div class="post-metadata">

**Author:** ![michael.tanner](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/michael.tanner/32/34_2.png) [@michael.tanner](https://forum.api.combocurve.com/u/michael.tanner)\
**Post date:** [December 29, 2021, 8:25pm UTC](https://forum.api.combocurve.com/t/pagination/33/3 "2021-12-29T20:25:35Z")

</div>

Will be super helpful! Thanks as always

---

<div class="post-metadata">

**Author:** ![michael.tanner](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/michael.tanner/32/34_2.png) [@michael.tanner](https://forum.api.combocurve.com/u/michael.tanner)\
**Post date:** [January 2, 2022, 3:32pm UTC](https://forum.api.combocurve.com/t/pagination/33/4 "2022-01-02T15:32:20Z")

</div>

CC Community - See below code chunk that builds upon @maikel.ruiz and team’s work using Python client package:

````auto
resultsList = []

def process_page(response_json):
    results = response_json["results"]
    resultsList.extend(results)

has_more = True

while has_more:
    response = requests.request("GET", urltwo, headers=auth_headers)
    urltwo = get_next_page_url(response.headers)
    process_page(response.json())
    has_more = urltwo is not None```
````

---

<div class="post-metadata">

**Author:** ![carlos.pena](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/carlos.pena/32/11_2.png) [@carlos.pena](https://forum.api.combocurve.com/u/carlos.pena)\
**Post date:** [January 3, 2022, 5:59pm UTC](https://forum.api.combocurve.com/t/pagination/33/5 "2022-01-03T17:59:17Z")

</div>

Building a bit more upon that, I would put that into a helper method that allows me to separate the logic for fetching and processing, and can be reused for other URLs. Something like this:

```auto
import requests
from combocurve_api_v1.pagination import get_next_page_url

# Helper method that returns an iterator with the documents from all pages
def get_all(url, headers):
    # First request
    has_more = True

    # Keep fetching while there are more records to be returned
    while has_more:
        response = requests.get(url, headers=headers)

        # Return the records to be processed by the caller instead of doing the processing here
        yield from response.json()

        url = get_next_page_url(response.headers)
        has_more = url is not None

```

Afterwards it can be used like this:

```auto
url = 'https://api.combocurve.com/v1/wells?take=200'
auth_headers = combocurve_auth.get_auth_headers()

for record in get_all(url, auth_headers):
    # Process each record (each well in this case) here
    print(record)

```

---

<div class="post-metadata">

**Author:** ![michael.tanner](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.api.combocurve.com/michael.tanner/32/34_2.png) [@michael.tanner](https://forum.api.combocurve.com/u/michael.tanner)\
**Post date:** [January 3, 2022, 8:24pm UTC](https://forum.api.combocurve.com/t/pagination/33/6 "2022-01-03T20:24:08Z")

</div>

Oh that even better!
