Skip to content

Commit

Permalink
PersonioClientV1: always specify limit/offset and honor new max page …
Browse files Browse the repository at this point in the history
…size 100
  • Loading branch information
lyind committed Oct 17, 2024
1 parent 33380b7 commit ceaed56
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit ceaed56

Please sign in to comment.