Pagination and limits
Fixed page sizes, an offset, and the ceilings you will hit.
3 min read
Search endpoints return { data, total }. You move through the results with offset, and total tells you when to stop. There is no limit parameter: the page size is fixed per endpoint, and it is not the same number for all three.
| Endpoint | Records per page |
|---|---|
| /api/v2/bookings/{pcode}/search | 20 |
| /api/v2/bookings/{pcode}/search/only-single | 15 |
| /api/v2/bookings/{pcode}/search/only-groups | 5 |
Do not hardcode 20
Advancing with
offset += 20 on the groups endpoint skips three quarters of the results in silence. Advance by the length of data you just received, and stop when offset + data.length >= total.javascript
1import { compactDecrypt, importPKCS8 } from 'jose'23// The private key saved when the API key was created — see Encrypted responses.4const privateKey = await importPKCS8(process.env.HOTELGEST_PRIVATE_KEY, 'RSA-OAEP-256')56const open = async (e) => {7 const jwe = [e.protected, e.wrappedKey, e.iv, e.payload, e.tag].join('.')8 const { plaintext } = await compactDecrypt(jwe, privateKey)9 return JSON.parse(new TextDecoder().decode(plaintext))10}1112let offset = 013const all = []1415for (;;) {16 const url = new URL('https://uni-api.hotelgest.com/api/v2/bookings/1234/search')17 url.searchParams.set('offset', String(offset))1819 const envelope = await fetch(url, {20 headers: { 'x-api-key': process.env.HOTELGEST_API_KEY },21 }).then((response) => response.json())22 const { data, total } = await open(envelope)2324 all.push(...data)25 offset += data.length2627 // Both conditions matter: `total` ends a normal walk, and an empty page ends28 // one where rows moved underneath you between requests.29 if (data.length === 0 || offset >= total) break30}
jose. Every key issued now answers encrypted, so each page is opened before data and total are read. A key issued before encryption answers in plain JSON: skip open and read the body as it comes.Rate limits
| Counter | Ceiling | Scope |
|---|---|---|
| Per source IP | 100 / minute | Every request from that IP, whatever the key or endpoint — usually the first one a client sending from a single server or serverless function meets |
| Per API key | 120 / minute | All endpoints together, not per endpoint |
| Per property | 300 / minute | Every key of that property — rotating keys buys nothing |
Repeat offences are blocked for longer
Each limit counts in a 60-second window that starts with your first request, and every response tells you where you stand in
X-RateLimit-Limit-<limit>, X-RateLimit-Remaining-<limit> and X-RateLimit-Reset-<limit> (seconds), where <limit> is apikey-ip, apikey or apikey-pcode. Going over one returns a 429 with the seconds to wait in Retry-After-<limit>, named after the limit you hit. The per-IP block lasts 60 seconds. The per-key and per-property blocks grow with every repeat offence, from 5 minutes up to 7 days, and the count of offences only resets after 14 days without going over. A request rejected by the per-IP limit still counts towards your key and your property: keep sending after a 429 and a one-minute block becomes one that lasts days. Stop every request in flight and wait out Retry-After-<limit>.