Authentication
Authenticate API requests with your secret key in the x-secret-key header. Where to find your keys and which one goes where.
Every API request carries your secret key in the x-secret-key header. The API does not use an Authorization: Bearer header.
POST /api/session/v1/create HTTP/1.1
Host: {your-domain}.api.sandbox.altruon.io
Content-Type: application/json
x-secret-key: sk_sandbox_...curl "https://{your-domain}.api.sandbox.altruon.io/api/v1/transaction/{transactionId}/details" \
-H "x-secret-key: $ALTRUON_SECRET_KEY"Secret key and publishable key
Altruon gives you two keys. They are not interchangeable.
| Secret key | Publishable key | |
|---|---|---|
| Sandbox format | sk_sandbox_... | pk_sandbox_... |
| Where it runs | Your server only | The browser |
| How you send it | x-secret-key header on every API request | First argument of altruon.init() in Altruon.js |
| What it does | Creates sessions and reads transaction details | Initializes the embedded payment component for your domain |
Which keys you need depends on your checkout:
- Hosted pages need no key. You build them in the backoffice.
- Dynamic hosted checkout needs the secret key, on your server, to create the session.
- Altruon.js needs both: the secret key on your server to create the session, and the publishable key in the browser. See Altruon.js.
Find your keys
Sign in to the backoffice and open Settings > API Keys. Both the secret key and the publishable key are listed there.
Sandbox and production
Sandbox and production are separate environments with separate hosts. Send sandbox keys to the sandbox host, and build and test there before you go live.
| Environment | API base URL |
|---|---|
| Sandbox | https://{your-domain}.api.sandbox.altruon.io |
| Production | https://{your-domain}.api.altruon.io |
Keep the secret key on your server
Never put the secret key in client-side code
Anyone who has it can create sessions and read transaction details for your account. The browser should only ever receive a session_id or a checkout_url.
- Create sessions and fetch transaction details from your backend only.
- Load the key from an environment variable. Do not hard-code it or commit it.
- Do not log the key.
- Use only the publishable key in the browser.
Failed authentication
A request with a missing or invalid secret key is rejected with HTTP 401 and the error code unauthorized. Check that the header is named x-secret-key and that it holds the secret key, not the publishable key. See Errors.
Webhook signing secrets
Webhooks do not use these keys. Each webhook endpoint has its own signing secret (whsec_...) that you use to check that a delivery came from Altruon. See Verify signatures.