Calls
Paginated Requests
4 min
several calls in the api return large lists of items in order to moderate bandwidth, the api will break up these returns into smaller sets, and you will have to make multiple calls in order to collect all of the information the limit per page is 50 items code samples the code samples below will show you how to paginate through a get user list call inspecting the basic return first, if you're unsure of the amount of users which will be included in the return, you can begin by making the call with starting position not included in doc this will give you information on what you can expect from the return import requests import json users endpoint = https //www regpack com/reg/api2/users/ headers = { "content type" "application/json", "accept" "application/json", "api id" "15263", "api user" "api admin\@regpacks com", "api token" "cd2e514f 7gab 3cde 62fg 51abcd4e7362", } payload = { "action" "get user list", "group id" 100909072, "doc" { } } get user list json = json dumps(payload) get user list response = requests post(url=users endpoint, data=get user list json, headers=headers, timeout=10) in the top of the response, total users will show you the total number of users in the return, while records per page will tell you how many will be included in each page { "totals" { "total users" 222, "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "records per page" "50", "balance" 0, "total children" 8, "label" "families", "group type" 1 } } making the paginated call the things to note here are that you need to increment starting position for each call inside the loop, this variable is updated within payload , and the parent and child users are added to the dictionary final return total users is the continuationof the previous code snippet import requests import json group id = 100908752 api id = "23366" api user = "rpapi+roger 1\@regpacks com" api token = "17387d82 e648 479d 89ca 0f4df7e0c0b8" users endpoint = 'https //www regpack com/reg/api2/users/' status endpoint = 'https //www regpack com/reg/api2/statuses/' headers = {'content type' 'application/json', 'accept' 'application/json', 'api id' api id, 'api user' api user, 'api token' api token} payload = { "action" "get user list", "group id" group id, "doc" { "starting position" 1 } } total users = 222 records per page = 50 calls required to get complete list = total users // records per page + 1 # // is the floor division operator pages = range(1, calls required to get complete list+1) # range's in python are exclusive, so add one parent users = \[] child users = \[] final return = {} for page in pages if page == 1 payload\["doc"]\["starting position"] = 0 if page != 1 payload\["doc"]\["starting position"] = payload\["doc"]\["starting position"] + records per page get user list json = json dumps(payload) get user list response = requests post(url=users endpoint, data=get user list json, headers=headers, timeout=10) json results = get user list response json() if "users" in json results keys() parent users extend(json results\["users"]) if "children" in json results keys() child users extend(json results\["children"]) final return update({"users" parent users, "children" child users}) print(json dumps(final return, indent=4)) and here would be the ouput (truncated) { "users" \[ { "u name" "miles davis quintet", "total forms" "2", "completed forms" "0", "total user forms" "2", "total completed user forms" "0", "total user mandatory forms" "2", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "75771", "status name" "confirmed attending", "status color" "#89bb1f", "application date" "oct 23rd 2021 20 28", "application date raw" "2021 10 23 20 28 21", "u comments" "0", "group id" "100908752", "uid" "4030267", "clogin id" "102670540", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" "5", "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "ed bickert trio", "total forms" "2", "completed forms" "0", "total user forms" "2", "total completed user forms" "0", "total user mandatory forms" "2", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 22", "application date raw" "2021 10 23 20 22 58", "u comments" "0", "group id" "100908752", "uid" "4030262", "clogin id" "102670535", "excluded" "0", "connected to" "102670535", "total user tags" "0", "user tag ids" null, "total non excluded children" "3", "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null } ], "children" \[ { "u name" "ed bickert", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" "0", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 23", "application date raw" "2021 10 23 20 23 34", "u comments" "0", "group id" "100908752", "uid" "4030263", "clogin id" "102670536", "excluded" "0", "connected to" "102670535", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "don thompson", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 24", "application date raw" "2021 10 23 20 24 39", "u comments" "0", "group id" "100908752", "uid" "4030264", "clogin id" "102670537", "excluded" "0", "connected to" "102670535", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "terry clarke", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 25", "application date raw" "2021 10 23 20 25 26", "u comments" "0", "group id" "100908752", "uid" "4030265", "clogin id" "102670538", "excluded" "0", "connected to" "102670535", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "miles davis", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 28", "application date raw" "2021 10 23 20 28 59", "u comments" "0", "group id" "100908752", "uid" "4030268", "clogin id" "102670541", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "wayne shorter", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 31", "application date raw" "2021 10 23 20 31 13", "u comments" "0", "group id" "100908752", "uid" "4030269", "clogin id" "102670542", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "herbie hancock", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 31", "application date raw" "2021 10 23 20 31 14", "u comments" "0", "group id" "100908752", "uid" "4030270", "clogin id" "102670543", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "ron carter", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 32", "application date raw" "2021 10 23 20 32 32", "u comments" "0", "group id" "100908752", "uid" "4030271", "clogin id" "102670544", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null }, { "u name" "tony williams", "total forms" "7", "completed forms" "0", "total user forms" "7", "total completed user forms" "0", "total user mandatory forms" "7", "total completed user mandatory forms" "0", "total order" "0 00", "total paid" "0 00", "total balance" "0 00", "user has saved payment method" " 1", "total items in cart" " 1", "status id" "0", "status name" null, "status color" null, "application date" "oct 23rd 2021 20 33", "application date raw" "2021 10 23 20 33 10", "u comments" "0", "group id" "100908752", "uid" "4030272", "clogin id" "102670545", "excluded" "0", "connected to" "102670540", "total user tags" "0", "user tag ids" null, "total non excluded children" null, "star" "0", "admin initials" null, "admin color" null, "assigned admin id" null } ] }