Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PersonioClientV1: always perform paging with max page size 100 #201

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/PersonioClientV1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** The Personio API v1 prefix. */
const PERSONIO_API_BASE_URL = 'https://api.personio.de/v1';

const PERSONIO_MAX_PAGE_SIZE = 100;


/** Simple wrapper around UrlFetchApp that performs authenticated requests against Personio API v1.
*
Expand Down Expand Up @@ -84,9 +86,13 @@ class PersonioClientV1 extends UrlFetchJsonClient {
do {
// we ensure only known Personio API endpoints can be contacted
let pathAndQuery = url;
if (offset != null) {
if (offset != null || !url.includes('offset=')) {
offset = Math.floor(Math.max(offset, 0));
pathAndQuery += pathAndQuery.includes('?') ? '&offset=' + offset : '?offset=' + offset;
}
if (!url.includes('limit=')) {
pathAndQuery += pathAndQuery.includes('?') ? '&limit=' + PERSONIO_MAX_PAGE_SIZE : '?limit=' + PERSONIO_MAX_PAGE_SIZE;
}

const document = await this.getJson(pathAndQuery, options);
if (!document || !document.success) {
Expand Down
Loading