Authentication
There are two ways to call the API:
- A secret API key, when you are the business, or build for one business, and call from its server.
- A connected app’s access token, when you build software many businesses use, and each business approves your app to act for it.
Both go in the Authorization header. Every request is made for exactly one business: the one
the key or the connection belongs to.
Secret API keys
Section titled “Secret API keys”Authorization: ApiKey sk_live_...Create keys in the dashboard under Settings > API keys. A business can hold several, for example one per server or per shop. Each has a name, so a list of keys stays readable.
- Test or live.
sk_test_keys work only on the sandbox,sk_live_keys only on the live API. The other server refuses them with403. - Refunds. A key can issue refunds only if Can refund is ticked for it. Without it,
refunds answer
403with error code1009. - Servers only. A secret key sent with an
Originheader, as every browser sends on a cross-site request, is refused, and the business is told the key may be exposed. - What a key can’t do. It can’t manage the business: no team, settings, payout account or other keys. Those stay in the dashboard, so a leaked key can’t take over the account.
Rolling a key
Section titled “Rolling a key”Roll a key from the same page when you want to replace it. You get a new key, and the old one keeps working for the time you choose, from none to 7 days (24 hours unless you change it), so you can deploy the new one without an outage. If a key has leaked, roll it with no grace period, or revoke it.
Key errors
Section titled “Key errors”| Status | errorCode |
Meaning |
|---|---|---|
401 |
8008 |
No key, or a key that doesn’t exist, expired or was revoked. |
403 |
1009 |
A key for the other server, a secret key sent from a browser, or a key that may not do this. The message says which. |
403 |
8001 |
The wrong kind of key, such as a publishable key on an endpoint that needs a secret key. |
Connected apps
Section titled “Connected apps”A connected app acts for businesses that approve it, through OAuth 2.0 authorization code with PKCE (RFC 6749, RFC 7636). It never sees the business’s keys. The business sees what it approved under Settings > Connected apps and can disconnect it there at any time.
Registering your app
Section titled “Registering your app”Spleetz registers connected apps. Contact Spleetz with:
- your app’s name, publisher, logo and links;
- the redirect addresses it will use:
https, orhttpto a loopback address while you develop, with no fragment; - the scopes it needs (below);
- its sources, if it has several parts that take payments, such as
invoicesandonline.checkout; - how it signs in: with a client secret, or with its own keys (see client authentication).
You get a client id (app_...) and, if you sign in with a secret, a client secret
(spz_cs_...), shown once.
Scopes
Section titled “Scopes”| Scope | What the business approves | Opens |
|---|---|---|
payments.create |
Take payments for you and cancel ones not yet paid | POST /transactions, POST /transactions/{id}/cancel |
payments.recurring |
Set up payments that repeat, and cancel them | recurring on POST /transactions, POST /recurring/{id}/cancel |
payments.read |
See the payments it takes for you | GET /transactions, GET /transactions/{id}, GET /recurring, GET /recurring/{id} |
refunds.create |
Refund the payments it takes for you | POST /transactions/{id}/refund |
settlements.read |
See the payouts made to your bank account | GET /settlements/payouts |
notifications.manage |
Get notified about the payments it takes for you | /webhook-endpoints |
An app reaches only endpoints opened to a scope it holds. Anything else answers 403 with
9958. An endpoint whose scope the connection lacks answers 403 with 9957 and a
WWW-Authenticate: Bearer error="insufficient_scope", scope="..." header.
An app sees only what its own connection created. Reads, cancels and refunds are limited to
payments made with that connection’s tokens. Payouts are the one exception: they are the
business’s, so settlements.read shows them all.
Sources
Section titled “Sources”If your app declares sources, every payment it creates must name one in source, and it must
be a source the business approved for the connection. The consent page shows the business each
source in your words. Ask for more later by sending the business through the flow again with
the new sources: the existing connection gains them once the business approves.
| Status | errorCode |
Meaning |
|---|---|---|
400 |
9955 |
The app doesn’t declare that source, or a caller that isn’t an app sent one. |
403 |
9956 |
The business hasn’t approved that source for this connection. |
1. Send the business to authorize
Section titled “1. Send the business to authorize”Make a PKCE verifier and challenge, then send the business’s browser to:
GET https://api.spleetz.com/connect/authorize ?response_type=code &client_id=app_example &redirect_uri=https://app.example.com/spleetz/callback &scope=payments.create payments.read notifications.manage &sources=invoices &state=af0ifjsldkj &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM &code_challenge_method=S256 &external_account_id=account-381 &external_account_name=Hillside Academy(URL-encode the values; they are shown plain here.)
| Parameter | |
|---|---|
response_type |
code. |
client_id |
Your app’s client id. |
redirect_uri |
One of your registered addresses, exactly. |
scope |
Space-separated scopes. |
sources |
Space-separated sources, if your app declares any. |
state |
Your own value, returned unchanged. Use it to stop request forgery. |
code_challenge |
Base64url SHA-256 of your verifier. |
code_challenge_method |
S256. plain is refused. |
external_account_id |
Optional. Your own id for the account being connected, such as one of your customers. One business can connect several of your accounts; each is a connection of its own. |
external_account_name |
Required with external_account_id. Shown to the business. |
mode |
Optional: live or test. Each server connects in its own mode only: the sandbox always makes test connections, and the live API refuses mode=test. |
Spleetz signs the person in, shows them your app and what it asks for, and lets them choose which of their businesses to connect. Only the business’s owner or an admin can approve. Someone with no business can set one up on the way.
The browser then comes back to your redirect_uri:
- approved:
?code=spz_ac_...&state=...; - declined:
?error=access_denied&state=...; - the business can’t take payments yet, when you asked for
payments.create:?error=temporarily_unavailable&error_description=...&state=.... Offer to connect again later.
An unknown client id, or a redirect address you didn’t register, is never redirected to. The person sees a Spleetz page saying what is wrong instead.
2. Exchange the code
Section titled “2. Exchange the code”The code lasts 2 minutes and works once.
curl https://api.spleetz.com/connect/token \ -u "app_example:$CLIENT_SECRET" \ -d grant_type=authorization_code \ -d code=spz_ac_... \ -d redirect_uri=https://app.example.com/spleetz/callback \ -d code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk{ "access_token": "spz_at_...", "token_type": "Bearer", "expires_in": 900, "refresh_token": "spz_rt_...", "scope": "payments.create payments.read notifications.manage", "sources": "invoices", "grant_id": 4821, "merchant_id": 1093, "merchant_name": "Hillside Academy", "external_account_id": "account-381", "livemode": true}Store the refresh token, and the grant_id and merchant_id with your account. Responses carry
Cache-Control: no-store.
3. Call the API
Section titled “3. Call the API”Authorization: Bearer spz_at_...An access token lasts 15 minutes. An expired, revoked or unknown token answers 401 with
9959 and WWW-Authenticate: Bearer error="invalid_token".
4. Refresh, and rotation
Section titled “4. Refresh, and rotation”curl https://api.spleetz.com/connect/token \ -u "app_example:$CLIENT_SECRET" \ -d grant_type=refresh_token \ -d refresh_token=spz_rt_...Each refresh returns a new access token and a new refresh token. The old refresh token is spent. Store the new one before you use the access token.
If a spent refresh token is presented again, Spleetz takes it as stolen: it revokes every token of the connection, and your app must send the business through the flow again. The same happens if a code is exchanged twice. So never refresh from two places at once with the same token.
A refresh returns tokens with the connection’s scopes. You don’t need to send scope; it
can’t narrow them, and naming a scope the connection doesn’t hold is refused with
invalid_scope.
5. Disconnect
Section titled “5. Disconnect”curl https://api.spleetz.com/connect/revoke \ -u "app_example:$CLIENT_SECRET" \ -d token=spz_rt_...Either token revokes the whole connection, with every token it holds and the notification
endpoints it registered. The answer is 200 whether or not the token was live. The business
can also disconnect your app from its dashboard; your next refresh then fails with
invalid_grant.
Token errors
Section titled “Token errors”/connect/token and /connect/revoke answer errors as RFC 6749 section 5.2 describes:
{ "error": "invalid_grant", "error_description": "The code has expired." }error |
Status | |
|---|---|---|
invalid_request |
400 |
A missing parameter, or the client authenticated more than one way. |
invalid_client |
401 |
The client couldn’t be authenticated, or the app is not active. |
invalid_grant |
400 |
The code or refresh token is not valid, expired, already used or revoked. |
invalid_scope |
400 |
A refresh asked for a scope the connection doesn’t hold. |
unsupported_grant_type |
400 |
Use authorization_code or refresh_token. |
Client authentication
Section titled “Client authentication”At /connect/token and /connect/revoke your app proves who it is in one of these ways.
Using more than one at once is refused.
With a client secret
Section titled “With a client secret”Send it with HTTP Basic (-u client_id:client_secret, as above), or as client_id and
client_secret form fields.
Spleetz can rotate your secret. The replaced one keeps working for a period agreed when it is rotated, so you can deploy the new one first.
With your own keys (private_key_jwt)
Section titled “With your own keys (private_key_jwt)”Your app can sign in with a key pair instead, so no secret from Spleetz has to be copied into
your deployment. Publish your public keys as a JWKS at an https address and give Spleetz that
address when you register. Then send a signed JWT
(RFC 7523) instead of a secret:
client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearerclient_assertion=<JWT>client_id may be left out. If you send it, it must match the JWT.
| Claim | Rule |
|---|---|
iss, sub |
Both your client id. |
aud |
https://api.spleetz.com/connect/token (live) or https://api-sandbox.spleetz.com/connect/token (sandbox). The server’s own base address is also accepted. |
exp |
At most 5 minutes after now. One minute of clock difference is allowed. |
jti |
A new unique value each time. An assertion is accepted once. |
kid (header) |
The id of the signing key in your JWKS. |
| Algorithm | RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 or ES512. Shared-secret algorithms such as HS256 are refused. |
Spleetz caches your keys for 10 minutes. When an assertion is signed by a key it hasn’t seen, it reads your JWKS again, so you can rotate keys without telling Spleetz: publish the new key, then start signing with it. If your JWKS can’t be read, the keys read before keep working.
An app that signs in with keys has no client secret. Every refusal answers invalid_client.
With jose:
import { SignJWT, importPKCS8 } from 'jose';import { randomUUID } from 'node:crypto';
const clientId = 'app_example';const tokenUrl = 'https://api.spleetz.com/connect/token';const key = await importPKCS8(process.env.SPLEETZ_SIGNING_KEY, 'ES256');
const assertion = await new SignJWT({}) .setProtectedHeader({ alg: 'ES256', kid: 'key-2026-11' }) .setIssuer(clientId) .setSubject(clientId) .setAudience(tokenUrl) .setIssuedAt() .setExpirationTime('2m') .setJti(randomUUID()) .sign(key);
const response = await fetch(tokenUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: storedRefreshToken, client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', client_assertion: assertion, }),});With Microsoft.IdentityModel.JsonWebTokens:
using System.Security.Cryptography;using Microsoft.IdentityModel.JsonWebTokens;using Microsoft.IdentityModel.Tokens;
var clientId = "app_example";var tokenUrl = "https://api.spleetz.com/connect/token";
var ecdsa = ECDsa.Create();ecdsa.ImportFromPem(Environment.GetEnvironmentVariable("SPLEETZ_SIGNING_KEY"));var key = new ECDsaSecurityKey(ecdsa) { KeyId = "key-2026-11" };
var assertion = new JsonWebTokenHandler().CreateToken(new SecurityTokenDescriptor{ Issuer = clientId, Audience = tokenUrl, Claims = new Dictionary<string, object> { ["sub"] = clientId, ["jti"] = Guid.NewGuid().ToString(), }, IssuedAt = DateTime.UtcNow, Expires = DateTime.UtcNow.AddMinutes(2), SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256),});Test connections
Section titled “Test connections”Against the sandbox, use https://api-sandbox.spleetz.com for /connect/authorize and
/connect/token. Every connection made there is a test connection, and its token response has
"livemode": false. A test
connection takes test payments only, and its notification endpoints hear about test payments
only. Live and test connections are separate: connecting in one mode doesn’t connect the other.