Skip to Content
ePay.lkDocs

Authentication & API keys

Authenticate server-to-server requests with a secret key in the Authorization header. Keys are scoped, per environment, and can be rolled without downtime.

Bearer secret keys

Every /v1 request is authenticated with a secret key sent as a Bearer token:

curl https://beta.api.epay.lk/v1/balance \
  -H "Authorization: Bearer $EPAY_SECRET_KEY"

Keys look like sk_<env>_<32 characters>:

PrefixEnvironment
sk_live_Production (beta.api.epay.lk)
sk_test_Sandbox (beta.sandbox-api.epay.lk)
sk_dev_Local development of ePay itself

Create keys in the dashboard under Developers → API keys. The full key is shown once; ePay stores only a keyed hash of it, so a lost key can't be recovered — create a new one.

Secret keys never go in a browser or app

A secret key can create payments and refunds on your account. Keep it on your server — in environment variables or a secrets manager — and never in front-end JavaScript, mobile apps, Git repositories, logs or support tickets. Browsers and apps should call your backend, which calls ePay.

Scopes

Each key carries a list of scopes. Give each integration only what it needs — for example, a reporting job needs payments:read and balance:read but not payments:write.

ScopeAllows
payments:writePOST /v1/payments, POST /v1/payments/:id/cancel
payments:readGET /v1/payments, GET /v1/payments/:id
refunds:writePOST /v1/refunds
refunds:readGET /v1/refunds, GET /v1/refunds/:id
payment_links:writePOST /v1/payment_links
payment_links:readGET /v1/payment_links/:id
events:readGET /v1/events, GET /v1/events/:id
balance:readGET /v1/balance
customers:readReserved for upcoming customer endpoints

A request with a valid key that lacks the scope fails with 403 permission_error / missing_scope.

Authentication errors

HTTPcodeMeaning
401api_key_missingNo Authorization: Bearer … header
401api_key_invalidMalformed, unknown, revoked or expired key
401api_key_environment_mismatche.g. an sk_test_ key sent to beta.api.epay.lk — use the matching hostname
401publishable_key_not_allowedA pk_… key was used on a secret-key endpoint
403missing_scopeThe key doesn't have the scope the endpoint requires
403merchant_not_activeProduction only: your business isn't verified/active yet
429rate_limitedToo many requests for this key — back off and retry

Rolling a key

Rotate keys periodically and immediately if one may have leaked. Rolling is zero-downtime:

  1. Create a new key with the same scopes.
  2. Deploy it to your servers and confirm traffic is using it — the dashboard shows each key's last used time.
  3. Revoke the old key. Revocation is immediate; any request still using it gets 401 api_key_invalid.

If a key is exposed (pushed to a public repo, pasted in a chat, logged), revoke it first and investigate afterwards. Review the Activity log for actions taken with it.

Publishable keys

Publishable keys (pk_live_… / pk_test_…) are reserved for future client-side features. No endpoint accepts them today. Everything in this documentation uses secret keys from your server.

Dashboard sessions are separate

The merchant dashboard uses its own cookie-based sessions with CSRF protection and optional TOTP two-factor authentication. Those sessions can't call /v1, and API keys can't sign in to the dashboard.

On this page