Page through results with the BizPrint Print API
This page explains how the BizPrint Print API splits long lists into pages, and how to read every page. It is for developers who list printers or print jobs from their own app or website with the Print API.
Two Print API requests return lists, and both work the same way:
GET /printers, described in List printers with the BizPrint Print API.GET /jobs, described in Check print job status with the BizPrint Print API.
Choose the page and page size
Section titled “Choose the page and page size”Add these query parameters to a list request:
| Query parameter | What it does |
|---|---|
perPage |
How many items to return on each page, from 1 to 100. The default is 10. |
page |
Which page to return. The first page is 1, which is also the default. |
For example, this request asks for the second page of print jobs, 50 jobs per page:
GET https://print.bizswoop.app/api/connect-application/v1/jobs?perPage=50&page=2&publicKey=YOUR_PUBLIC_KEY&time=YOUR_TIMESTAMP&hash=YOUR_SIGNATUREperPage and page are part of the query string, so they are included when you sign the request. Sign each page request separately, with a fresh time. See Sign BizPrint Print API requests.
A perPage above 100, or a page below 1, returns a 400 error with the code ERR_INVALID_REQUEST. The errors field in the response names the parameter that is wrong. See BizPrint Print API error codes and how to fix them.
Read the pagination headers
Section titled “Read the pagination headers”The items are in the data list in the response body. The response headers tell you where you are in the whole list:
| Header | What it means |
|---|---|
X-Biz-Has-More |
true if there are more items after this page, false if this is the last page. |
X-Biz-Total-All |
The total number of items in the whole list. |
X-Biz-Total-Pages |
The total number of pages, for the perPage you asked for. |
Header values arrive as text, so compare X-Biz-Has-More with the text true, and turn the totals into numbers before you use them.
If you ask for a page after the last one, you get an empty data list and X-Biz-Has-More is false.
Read every page
Section titled “Read every page”To read a whole list:
- Send the list request with
page=1and theperPageyou want. - Add the items in
datato your results. - Read the
X-Biz-Has-Moreheader. - Stop if the header is
false. - Add 1 to
pageif the header istrue. - Sign the new request.
- Send it, and go back to step 2.
Here is the same loop in JavaScript for Node.js 18 or later, run on your server. The signQuery function adds publicKey, time and hash to the query, as described in Sign BizPrint Print API requests. It reads the keys from environment variables, so your Secret Key stays on your server.
import { createHash } from 'node:crypto';
const BASE_URL = 'https://print.bizswoop.app/api/connect-application/v1';const publicKey = process.env.BIZPRINT_PUBLIC_KEY; // YOUR_PUBLIC_KEYconst secretKey = process.env.BIZPRINT_SECRET_KEY; // YOUR_SECRET_KEY, server only
// Adds publicKey, time and hash, and returns the signed query string.function signQuery(params) { const query = new URLSearchParams(params); query.set('publicKey', publicKey); query.set('time', String(Math.floor(Date.now() / 1000))); const hash = createHash('sha256') .update(`${query.toString()}:${secretKey}`) .digest('hex'); query.set('hash', hash); return query.toString();}
export async function listAll(path) { const items = []; let page = 1; let hasMore = true;
while (hasMore) { const query = signQuery({ perPage: 100, page }); const response = await fetch(`${BASE_URL}${path}?${query}`); const body = await response.json();
if (!response.ok) { throw new Error(`${body.errorCode}: ${body.message}`); }
items.push(...body.data); hasMore = response.headers.get('X-Biz-Has-More') === 'true'; page += 1; }
return items;}
// const printers = await listAll('/printers');Things to know
Section titled “Things to know”- Print jobs are sorted oldest first. The
GET /jobslist starts with your oldest job, so your newest jobs are on the last page. UseX-Biz-Total-Pagesto go straight to the last page. - Lists can change while you read them. If a new print job is created or a station reports a new printer while you are paging, items can move between pages. Treat the list as a snapshot, and remove duplicates by
idif you need an exact list. - Only list what you need. If you already have a job’s ID, look it up directly with
GET /jobs/{id}instead of reading the whole list.
Related pages
Section titled “Related pages”- List printers with the BizPrint Print API
- Check print job status with the BizPrint Print API
- BizPrint Print API error codes and how to fix them
- Sign BizPrint Print API requests
Need help? Contact BizPrint support at https://getbizprint.com/support/.