Paging through list requests
All list endpoints in the Inkit API, such as List Documents, List Batches, List Folders, List Templates and List Flow Statuses, paginate their results for the purposes of efficiency. To iterate through the entire list of the objects that these endpoints return, you must process data from the metadata.pagination
object.
Here is an example of how to iterate through the entire list of documents:
# Import the Inkit Python package
import inkit
from inkit.exceptions import InkitResponseException
# Import json package
import json
# Replace the string below with your API key
inkit.api_token = "ENTER YOUR API KEY"
try:
# Get first page of documents and folders created
resp = inkit.Document.list()
# Find the total number of pages
page_count = resp.data.metadata.pagination.page_count
# Iterate through the pages
for page in range(1, page_count):
# Print all items in the current page
for item in resp.data.items:
print(json.dumps(item, indent = 3))
# Find the current page
current_page = resp.data.metadata.pagination.current_page
# Get the next page if there is one
if current_page < page_count:
resp = inkit.Document.list(page = current_page + 1)
except InkitResponseException as err:
# Print any error
print(err.response.data)
// Import the Inkit Node.js package
const Inkit = require("inkit");
// Replace the string below with your API key
Inkit.apiToken = "ENTER YOUR API KEY";
// Call list all documents
listAllDocuments();
// List all documents
async function listAllDocuments() {
try {
// Get first page of documents and folders created
var result = await Inkit.Document.list();
// Find the total number of pages
var pageCount = result.data.metadata.pagination.page_count;
// Iterate through the pages
for (page = 1; page <= pageCount; page++) {
// Print all items in the current page
for (item in result.data.items) {
console.log(JSON.stringify(result.data.items[item], null, 3));
}
// Find the current page
let currentPage = result.data.metadata.pagination.current_page;
// Get the next page if there is one
if (currentPage < pageCount) {
result = await Inkit.Document.list({page: currentPage + 1});
}
}
} catch (error) {
// Print any error
console.error(error.response.status, error.response.statusText);
}
}
{
"created_at": "2023-07-13T15:20:29.270479Z",
"created_by": {
"first_name": "John",
"last_name": "Doe",
"name": "Default"
},
"description": null,
"id": "fold_6UpetHRzr73eyl4jCbfYBl",
"modified_at": "2023-07-13T15:20:29.270491Z",
"name": "Render"
}
{
"created_at": "2023-09-06T13:46:52.520285Z",
"created_by": {
"first_name": null,
"last_name": null,
"name": "Sally Smith"
},
"description": null,
"expire_after_n_views": null,
"expire_at": null,
"folder_id": null,
"id": "doc_IAjDpXZR1PKPXmkWttJFE",
"name": "I-9",
"render_id": "rend_5oGScGXBnDpKJbXnm4u6J7",
"status": "Completed"
}
How to iterate through a list of documents
Open Recipe
Updated 12 months ago