Recipes / Integration patterns
FoundationsThe habits every solid integration shares: token handling, pagination, error handling, money and date conventions, id resolution.
Distilled from nine production integrations.
Every call needs a bearer token, and there is no password endpoint to get one from: POST /api/auth/login was removed in September 2026. There is one way in, and it is the same whether your integration runs nightly on a server or on somebody's desk.
An integration authenticates with an API key. Your Storekeeper administrator creates one for you in the Storekeeper app and hands you two values. The client_id looks like sk_ak_<account>.<key_id>. It names its own account, so you can discover that account's token endpoint instead of hard-coding it. You exchange the pair for an access token with client_credentials (RFC 6749 §4.4), which any stock OAuth client library does without bespoke code.
# discover, then exchange. The exchange happens AT STOREKEEPER:
# this API never sees, holds or brokers your secret.
curl -s https://api-$ACCOUNT.storekeepercloud.com/.well-known/oauth-authorization-server \
| jq -r .token_endpoint
curl -s -X POST https://api-$ACCOUNT.storekeepercloud.com/oauth/token \
-u "$SK_CLIENT_ID:$SK_CLIENT_SECRET" \
-d grant_type=client_credentials
The exchange is cheap and repeatable, so a client does not need to hoard tokens. Get one at startup, and get another when it expires or when a call answers 401. One key serves one integration. The per-key rate limit exists to keep it that way, so give each integration its own key. Adding workers on one key does not buy throughput; it splits one budget more ways.
Every authenticated response tells you where you stand: RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset (seconds until the window rolls). Read RateLimit-Remaining as you page through a list and slow down before it reaches zero. That is the number to pace against. The ceiling is deployment configuration, so a rate copied from a documentation page goes stale the day it is tuned. Past the ceiling you get a 429 with Retry-After: sleep exactly that many seconds and carry on. Retrying immediately spends the next window on refusals as well. Writes (POST, PUT, PATCH, DELETE) are charged against a second, tighter counter on top of the general one, so a sync that reads a lot and writes a little meets the write ceiling first.
Two further headers say the same thing with the ceiling named. RateLimit-Policy lists every ceiling that applies to your key. There are two, general and write, each with its quota (q) and its window in seconds (w). The header is built from configuration rather than from your request, so even a GET carries the write ceiling; a client that has only read so far still learns what is waiting for its first write. RateLimit then reports the state of exactly one ceiling, the one closest to refusing you next, and names it. r is what is left and t the seconds until it resets, the same two numbers as RateLimit-Remaining and RateLimit-Reset. That name is what a mixed read/write loop needs. When the remaining count jumps from a small number to a large one, the name tells you the counter changed. On a 429 it names the ceiling that refused, with r=0. A response carrying none of the five was not counted at all (an unauthenticated call, or a minute we could not measure), so read absence as "no budget reported" and never as zero.
{
"access_token": "eyJ0eXAiOiJhdCtqd3Qi...",
"token_type": "Bearer",
"expires_in": 900
}
There is no renew endpoint on this API, and you do not need one. When
expires_in runs out you exchange the key again. It is the same call, as cheap the
second time as the first. Nothing is revoked, rotated or consumed by exchanging, so a
client that asks for a token whenever it needs one is the correct client.
# the shape of a well-behaved client, in pseudocode
token, ttl = exchange_api_key() # client_credentials, at Storekeeper
loop:
if now > issued_at + ttl - 60: # get another a minute before it expires
token, ttl = exchange_api_key()
resp = call(endpoint, token)
if resp.status == 401: # belt and braces: token expired anyway
token, ttl = exchange_api_key()# re-exchange ONCE
resp = call(endpoint, token) # retry ONCE, then fail loudly
if resp.status == 429: # over the ceiling for this minute
sleep(resp.header["Retry-After"]) # exactly that long, then carry on
if resp.header["RateLimit-Remaining"] < resp.header["RateLimit-Limit"] / 10:
slow_down() # pace off the headers, not a hard-coded rate
# resp.header["RateLimit"] names the ceiling those
# numbers came from: "general" or "write"
# a 401 on the exchange itself means the key is dead, so do not retry:
# it has been revoked or rolled, and a human has to issue a new one.
GET /api/me tells you who the token belongs to, and which capabilities the key's
role actually holds. Call it once at startup as a sanity check that you are on the account
you think you are, with the authority you think you have.
expires_in is deployment configuration rather than a constant, so do not hard-code 900 or 1800. Do not parse the token, do not persist it beyond its TTL, and do not share one between two workers. Give each worker its own session.Every list endpoint answers with the same envelope: count (rows on this page), total (rows overall), data (the rows), and echoes your start and limit. The loop is always the same: request, append data, add count to start, repeat while start < total. "Fewer rows than limit" is a hint at best; total is authoritative.
start=0; limit=200
while start < total:
GET /api/product?start=$start&limit=$limit
rows += data
start += count
Keep limit sane: 100 to 250 is the sweet spot. Bigger pages save little and make each retry more expensive; tiny pages multiply round trips. Date-range parameters (from, to) are inclusive on both ends and interpreted in Europe/Amsterdam, so from=2026-06-01&to=2026-06-30 is exactly the month of June.
Errors come back as an RFC 9457 problem document (Content-Type: application/problem+json) with a stable shape. type is the identifier to branch on, or about:blank where the problem carries no meaning beyond the status code. title is the status phrase. status repeats the HTTP code as a number, for logs that only keep bodies. detail says what actually went wrong. What to do depends on the class rather than the endpoint:
| Status | Meaning | What to do |
|---|---|---|
400 | Your input is malformed (bad filter, bad body) | Fix the request. Retrying it unchanged fails identically forever. |
401 | Token missing, invalid, or expired | Exchange the key again once, retry once. |
404 | The id does not exist on this account | Check which account your key belongs to; ids are per-account. |
502 | Upstream Storekeeper error | Safe to retry with backoff (e.g. 2s, 8s, 30s); it is transient more often than not. |
{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "`product_ids` entry 2 must be a whole number of at least 1. The string \"abc\" is not one, and a query value this API cannot read is refused rather than guessed.",
"trace_id": "9f1c0a2e-6b7d-4c33-9a10-5b2e8d4f1c07"
}
Log the full error body, not just the status code. The detail is written to be actionable, a 401 additionally carries a hint field telling you where a token comes from, and trace_id repeats the X-Request-Id header. A pasted body is therefore enough on its own for us to find the call in our logs. A log line that says only "400" costs a debugging session; the body would have named the parameter.
All money is decimal euros. The suffix convention is consistent across the whole API: _wt means "with tax" (including VAT), a plain field or an _ex suffix means excluding VAT. Where a price or a total matters, the API gives you both sides plus the VAT itself. Use them as given. Your rounding will not match Storekeeper's, and a price list that is one cent off the till is worse than no price list.
Dates are YYYY-MM-DD, interpreted in Europe/Amsterdam, and ranges are inclusive on both ends. A day boundary is a Dutch midnight rather than UTC: a sale at 00:30 Amsterdam time on July 1st belongs to July, even though it is still June 30th in UTC.
The API speaks in numeric ids. Each id space has one reference endpoint; call each once at the start of a sync, cache the mapping in memory, and translate at the edges of your system. Do not hardcode ids across accounts.
| Id field | Resolve via | Note |
|---|---|---|
shop_id | GET /api/shop | A sales channel (webshop, POS). |
location_id | GET /api/location | A physical site. |
tax_rate_id | GET /api/tax-rate?country_code=NL | Filter, or you get the whole EU registry. |
product_group_id | GET /api/turnover-group | Turnover groups double as revenue-ledger keys. |
provider_method_type_id | GET /api/payment-method | Ids are per-account; base your mapping on the stable type_alias. |
location_id will not accept a shop id, and vice versa; keep the two mappings separate in your code.Recepten / Integratiepatronen
BasisDe gewoonten die elke degelijke integratie deelt: omgaan met tokens, paginering, foutafhandeling, geld- en datumconventies, id-vertaling.
Gedistilleerd uit negen productie-integraties.
Elke aanroep heeft een bearer-token nodig, en er is geen wachtwoord-endpoint meer om er een te halen: POST /api/auth/login is in september 2026 verwijderd. Er is één manier, en die is dezelfde of je integratie nu 's nachts op een server draait of op iemands bureau.
Een integratie authenticeert met een API-sleutel. Je Storekeeper-beheerder maakt er een voor je aan in de Storekeeper-app en geeft je twee waarden. De client_id ziet eruit als sk_ak_<account>.<key_id>. Hij noemt zijn eigen account, dus je kunt het token-endpoint van dat account opzoeken in plaats van het hard te coderen. Je wisselt het paar in voor een access token met client_credentials (RFC 6749 §4.4), en dat doet elke standaard OAuth-clientbibliotheek zonder maatwerk.
# opzoeken, dan inwisselen. Het inwisselen gebeurt BIJ STOREKEEPER:
# deze API ziet, bewaart en bemiddelt je secret nooit.
curl -s https://api-$ACCOUNT.storekeepercloud.com/.well-known/oauth-authorization-server \
| jq -r .token_endpoint
curl -s -X POST https://api-$ACCOUNT.storekeepercloud.com/oauth/token \
-u "$SK_CLIENT_ID:$SK_CLIENT_SECRET" \
-d grant_type=client_credentials
Het inwisselen is goedkoop en herhaalbaar, dus een client hoeft geen tokens te hamsteren. Haal er een bij het opstarten, en nog een zodra het verloopt of een aanroep 401 antwoordt. Eén sleutel is voor één integratie. De limiet per sleutel bestaat om dat zo te houden, dus geef elke integratie een eigen sleutel. Workers bijzetten op één sleutel levert geen doorvoer op; het verdeelt één budget over meer workers.
Elk geauthenticeerd antwoord vertelt je waar je staat: RateLimit-Limit, RateLimit-Remaining en RateLimit-Reset (seconden tot het venster rolt). Lees RateLimit-Remaining terwijl je een lijst doorloopt en schakel terug voordat hij nul bereikt. Dat is het getal om je tempo op te bepalen. Het plafond is deployment-configuratie, dus een tempo dat je uit een documentatiepagina overneemt is achterhaald op de dag dat het wordt bijgesteld. Boven het plafond krijg je een 429 met Retry-After: wacht precies zoveel seconden en ga daarna verder. Wie meteen opnieuw probeert, verbruikt ook het volgende venster aan weigeringen. Schrijfacties (POST, PUT, PATCH, DELETE) worden op een tweede, strengere teller afgeschreven bovenop de algemene, dus een sync die veel leest en weinig schrijft loopt eerst tegen de schrijflimiet aan.
Twee extra headers zeggen hetzelfde, maar met het plafond erbij genoemd. RateLimit-Policy somt elk plafond op dat voor jouw sleutel geldt. Het zijn er twee, general en write, elk met een quotum (q) en een venster in seconden (w). De header wordt uit de configuratie opgebouwd en niet uit je verzoek, dus ook een GET draagt het schrijfplafond; een client die tot nu toe alleen las, weet zo al wat er op zijn eerste schrijfactie wacht. RateLimit geeft vervolgens de stand van precies één plafond, het plafond dat je als eerste gaat weigeren, en noemt het erbij. r is wat er over is en t het aantal seconden tot het opnieuw begint, dezelfde twee getallen als RateLimit-Remaining en RateLimit-Reset. Die naam is precies wat een lus die leest én schrijft nodig heeft. Springt het resterende aantal van een klein naar een groot getal, dan zie je aan de naam dat het een andere teller was. Bij een 429 noemt hij het plafond dat weigerde, met r=0. Een antwoord dat geen van de vijf draagt, is helemaal niet geteld (een niet-geauthenticeerde aanroep, of een minuut die we niet konden meten), dus lees het ontbreken als "geen budget gemeld" en nooit als nul.
{
"access_token": "eyJ0eXAiOiJhdCtqd3Qi...",
"token_type": "Bearer",
"expires_in": 900
}
Deze API heeft geen ververs-endpoint, en je hebt er ook geen nodig. Is
expires_in op, dan wissel je de sleutel gewoon opnieuw in. Het is dezelfde aanroep,
de tweede keer net zo goedkoop als de eerste. Inwisselen trekt niets in, roteert niets en
verbruikt niets, dus een client die om een token vraagt wanneer hij er een nodig heeft,
is de juiste client.
# de vorm van een nette client, in pseudocode
token, ttl = exchange_api_key() # client_credentials, bij Storekeeper
loop:
if now > issued_at + ttl - 60: # haal een nieuwe, een minuut voor het verloopt
token, ttl = exchange_api_key()
resp = call(endpoint, token)
if resp.status == 401: # dubbel gedekt: token toch verlopen
token, ttl = exchange_api_key()# ÉÉN keer opnieuw inwisselen
resp = call(endpoint, token) # ÉÉN keer herhalen, daarna luid falen
if resp.status == 429: # over het plafond van deze minuut
sleep(resp.header["Retry-After"]) # precies zo lang, dan verder
if resp.header["RateLimit-Remaining"] < resp.header["RateLimit-Limit"] / 10:
slow_down() # tempo uit de headers, niet hard gecodeerd
# resp.header["RateLimit"] noemt van welk plafond
# die getallen kwamen: "general" of "write"
# een 401 op het inwisselen zelf betekent een dode sleutel, dus niet opnieuw proberen:
# hij is ingetrokken of vervangen, en een mens moet een nieuwe uitgeven.
GET /api/me vertelt je van wie het token is, en welke capabilities de rol van de
sleutel echt heeft. Roep het één keer bij het opstarten aan als controle dat je op het
juiste account zit, met de rechten die je denkt te hebben.
expires_in is deployment-configuratie in plaats van een constante, dus hardcode geen 900 of 1800. Parse het token niet, bewaar het niet langer dan zijn TTL, en deel er geen tussen twee workers. Geef elke worker zijn eigen sessie.Elk lijst-endpoint antwoordt met dezelfde envelop: count (regels op deze pagina), total (regels in totaal), data (de regels), en echoot je start en limit. De lus is altijd hetzelfde: opvragen, data toevoegen, count bij start optellen, herhalen zolang start < total. "Minder regels dan de limiet" is hooguit een hint; total is leidend.
start=0; limit=200
while start < total:
GET /api/product?start=$start&limit=$limit
rows += data
start += count
Houd limit verstandig: 100 tot 250 is de gulden middenweg. Grotere pagina's leveren weinig op en maken elke retry duurder; piepkleine pagina's vermenigvuldigen het aantal aanroepen. Datumbereik-parameters (from, to) zijn aan beide kanten inclusief en worden geïnterpreteerd in Europe/Amsterdam, dus from=2026-06-01&to=2026-06-30 is precies de maand juni.
Fouten komen terug als een RFC 9457-probleemdocument (Content-Type: application/problem+json) met een stabiele vorm. type is de identifier waarop je vertakt, of about:blank waar de fout niets betekent bovenop de statuscode. title is de statusomschrijving. status herhaalt de HTTP-code als getal, voor logs die alleen bodies bewaren. detail zegt wat er echt misging. Wat je moet doen hangt af van de klasse en niet van het endpoint:
| Status | Betekenis | Wat te doen |
|---|---|---|
400 | Je input klopt niet (fout filter, foute body) | Herstel het verzoek. Ongewijzigd herhalen faalt eeuwig op dezelfde manier. |
401 | Token ontbreekt, is ongeldig of verlopen | Wissel de sleutel één keer opnieuw in, herhaal één keer. |
404 | Het id bestaat niet op dit account | Controleer bij welk account je sleutel hoort; ids zijn per account. |
502 | Fout bij Storekeeper zelf | Veilig om te herhalen met backoff (bijv. 2s, 8s, 30s); meestal tijdelijk. |
{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "`product_ids` entry 2 must be a whole number of at least 1. The string \"abc\" is not one, and a query value this API cannot read is refused rather than guessed.",
"trace_id": "9f1c0a2e-6b7d-4c33-9a10-5b2e8d4f1c07"
}
Log de volledige foutbody, niet alleen de statuscode. De detail is geschreven om bruikbaar te zijn, een 401 draagt bovendien een hint-veld dat zegt waar een token vandaan komt, en trace_id herhaalt de X-Request-Id-header. Een geplakte body is daarmee op zichzelf genoeg om de aanroep in onze logs terug te vinden. Een logregel die alleen "400" zegt kost een debugsessie; de body had de parameter genoemd.
Al het geld is in decimale euro's. De suffix-conventie is overal in de API gelijk: _wt betekent "with tax" (inclusief btw), een veld zonder suffix of met _ex betekent exclusief btw. Waar een prijs of totaal ertoe doet, geeft de API je beide kanten plus de btw zelf. Gebruik ze zoals ze zijn. Jouw afronding komt niet overeen met die van Storekeeper, en een prijslijst die één cent naast de kassa zit is erger dan geen prijslijst.
Datums zijn YYYY-MM-DD, geïnterpreteerd in Europe/Amsterdam, en bereiken zijn aan beide kanten inclusief. Een daggrens is Nederlandse middernacht en niet UTC: een verkoop om 00:30 Amsterdamse tijd op 1 juli hoort bij juli, ook al is het in UTC nog 30 juni.
De API spreekt in numerieke ids. Elke id-ruimte heeft één referentie-endpoint; roep elk daarvan één keer aan bij de start van een sync, cache de mapping in het geheugen, en vertaal aan de randen van je systeem. Hardcode nooit ids over accounts heen.
| Id-veld | Vertaal via | Opmerking |
|---|---|---|
shop_id | GET /api/shop | Een verkoopkanaal (webshop, kassa). |
location_id | GET /api/location | Een fysieke vestiging. |
tax_rate_id | GET /api/tax-rate?country_code=NL | Filter, anders krijg je het hele EU-register. |
product_group_id | GET /api/turnover-group | Omzetgroepen zijn tegelijk je omzetgrootboek-sleutels. |
provider_method_type_id | GET /api/payment-method | Ids zijn per account; baseer je mapping op de stabiele type_alias. |
location_id nemen, accepteren geen winkel-id en andersom; houd de twee mappings gescheiden in je code.