Skip to main content
Skip table of contents

Pagination

The Lucidum APIs can return multiple pages in a response. Lucidum recommends that you specify a page to return and the number of records to include in the page.

Pagination Syntax

To define pagination, include the following in the request body.

CODE
"paging": { 
     "page": 0,
     "recordsPerPage": 20
 }
  • “paging”:{. Specifies that that section between the curly braces (line 1 and line 4) describes pagination.

  • page. Specifies the page to return. Paging starts at “0” (zero).

  • recordsPerPage. Specifies the records to include per page. The default value is 20. The maximum value is 100.

Include the pagination information inside the curly braces that surround the data (curl) or body (python) of the request.

Python Example for Pagination


The following Python snippet, included at the end of a Python request to the Lucidum API, controls pagination:

CODE
if __name__ == '__main__':
    page = 0
    result= []
    sess = create_session()
    while True:
        payload['paging']['page'] = page
        resp = sess.post(url, data=json.dumps(payload), verify=False)
        data = resp.json()
        result = result + data['data']
        print("Total Result Records\t:", len(result))
        print("Page\t\t:", data['page'])
        if page < data['totalPages']:
            page = page + 1
        else:
            break
        time.sleep(1)
    print("Total Result Records\t:", len(result))

This code creates an infinite loop that will run until the page number is greater than the total pages. The code snippet produces pagination output like:

Total Result Records: 3 Page: 1

  • Line 2. The code defines a variable called “page and initializes the variable to be “0”

  • Line 3. The code defines a variable called “result“ as an empty list of records.

  • Line 4. The code defines a variable called “sess” as a session object with the create_session() method.

  • Line 5. This code creates an infinite loop (while True:) that will run until the page is greater than the total pages.

  • Line 6. The code defines the “page parameter of the “payload” dictionary, with 'paging' as its key and 'page' as its value. “payload” was defined earlier in another (unshown) part of the code and contains the query parameters for the POST request.

  • Line 7. The code then sends a POST request with the sess.post method. The POST uses the previously specified URL and includes the value of “payload”.

  • Line 8. The code uses the resp.json method to retrieve the JSON response from the POST request and assigns the response value the variable “data”

  • Line 9. The code appends the value of “data” to the “results” list.

  • Line 10 - Line 11. The script then uses the print() function to print the total number of records in the results list and the current page number.

  • Line 12 -Line 15. If the current page number is less than the total number of pages in the response, it increments the page variable by 1 and continues to the next iteration of the loop. Otherwise, it breaks out of the loop.

  • Line 16-Line 17. The script then waits for 1 second using the time.sleep() function and prints the total number of records in the result list again.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.