From ceaed568e43bd5be37c070e79dba7e43f62f4842 Mon Sep 17 00:00:00 2001 From: Jonas Zeiger Date: Thu, 17 Oct 2024 18:40:12 +0200 Subject: [PATCH] PersonioClientV1: always specify limit/offset and honor new max page size 100 --- lib/PersonioClientV1.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) {