Frequently asked questions

What is darvis/snelstart?

A PHP package with a client for the SnelStart B2B API v2, the API of the Dutch accounting software SnelStart. It fetches and keeps the access token, reads and writes every collection of the API with paging, and reports failures with their HTTP status and SnelStart error codes. It has no models, no synchronisation and no webhooks, and it returns the arrays SnelStart answers with.

How do I connect a Laravel application to the SnelStart API?

Run composer require darvis/snelstart, set SNELSTART_CLIENT_KEY and SNELSTART_SUBSCRIPTION_KEY in .env and check with php artisan snelstart:test. Then use the Snelstart facade, or inject Darvis\Snelstart\Client: Snelstart::relaties()->all(), Snelstart::verkooporders()->create($data), or get(), post(), put() and delete() for any other endpoint.

What do I need to use darvis/snelstart, and what does it cost?

PHP 8.2 or higher, and a client key and a subscription key for the B2B API, both issued by SnelStart. The subscription key comes from a subscription on the product “Ontwikkeling & Test” in the SnelStart developer portal (Profile, Subscriptions); the client key is generated on the “Maatwerk” tile under Koppelingen in SnelStart Web, by a user of the administration, and is shown once. The Laravel integration needs Laravel 11, 12 or 13; without Laravel the package needs the cURL extension. The package itself is free and MIT licensed; SnelStart charges for certifying an integration.

How does darvis/snelstart authenticate with SnelStart, and where is the access token kept?

It posts grant_type=clientkey and your client key as a form to the token endpoint and sends the token it gets in the Authorization header, with the subscription key in the Ocp-Apim-Subscription-Key header. In Laravel the token is kept in memory and, encrypted with the application key, in Laravel’s cache until sixty seconds before it expires; SNELSTART_TOKEN_CACHE=false keeps it in memory only. Without Laravel it is kept in memory, unless you give the client a token store of your own.

How do I get more than 500 rows from SnelStart?

Loop over all(): foreach ($snelstart->relaties()->all() as $relatie). It asks for 500 rows at a time with $skip and $top and fetches the next page only when your loop gets there. list() is a single call and returns what SnelStart gives for that one call.

What happens when a SnelStart call fails, and how do I read the error codes?

The client throws Darvis\Snelstart\Exceptions\SnelstartException, which extends RuntimeException. $e->status() gives the HTTP status, and 0 when there was no response, such as a timeout. $e->errorCodes() gives the SnelStart error codes in the response, such as REL-0007, and $e->errors() gives each code with the text SnelStart documents for it.

Does darvis/snelstart retry a failed call?

Only once, and only for a 401 on a token it already had: it fetches a new token and repeats the call. A 429, a 5xx and a timeout are not retried, so make such calls from a queued job with a backoff. A request gives up after 30 seconds, 10 to connect (SNELSTART_TIMEOUT, SNELSTART_CONNECT_TIMEOUT).

Can darvis/snelstart work with more than one SnelStart administration?

Yes. A client key belongs to one administration, and withClientKey($key) gives the same client for another key: Snelstart::withClientKey($key)->relaties()->list(). The clients share the subscription key and the token store, and tokens are kept per client key.

Is darvis/snelstart safe with my SnelStart keys?

The client key goes in the body of the token request and the subscription key and the token go in headers, never in a URL. The package replaces all three with [redacted] in its exception messages and command output, and in Laravel it only stores the token in the cache encrypted. The rest of an error response can hold data of the administration, so protect your logs.

How do I test code that uses darvis/snelstart without calling SnelStart?

In Laravel use Http::fake() for auth.snelstart.nl/* (return an access_token) and for b2bapi.snelstart.nl/*, set snelstart.client_key to any value and call Http::preventStrayRequests(). Without Laravel, give the client a Darvis\Snelstart\Testing\FakeTransport, which answers from a list and records what was sent.