Skip to content
getbizprint.com

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:

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_SIGNATURE

perPage 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.

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.

To read a whole list:

  1. Send the list request with page=1 and the perPage you want.
  2. Add the items in data to your results.
  3. Read the X-Biz-Has-More header.
  4. Stop if the header is false.
  5. Add 1 to page if the header is true.
  6. Sign the new request.
  7. 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_KEY
const 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');
  • Print jobs are sorted oldest first. The GET /jobs list starts with your oldest job, so your newest jobs are on the last page. Use X-Biz-Total-Pages to 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 id if 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.

Need help? Contact BizPrint support at https://getbizprint.com/support/.