diff --git a/lib/PersonioClientV1.js b/lib/PersonioClientV1.js index 883f7a9..63b5add 100644 --- a/lib/PersonioClientV1.js +++ b/lib/PersonioClientV1.js @@ -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. * @@ -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) {