# Authentication (/authentication) > Your backend sends its MPS API key in the Authorization header of every call. Your backend authenticates every call with an **API key**: one string, sent on every request. There is nothing to fetch, cache or refresh first. > **Server only.** The API cannot be called from a browser. The gateway answers no cross-origin (CORS) requests, and the API key must never reach a browser. Call it from your server. ```http POST https://gateway.mps-emi.com/api/payments/internet/create Authorization: Bearer mps_test_… Content-Type: application/json Idempotency-Key: 4f9c2e1a-7b3d-4c8e-9a1f-0d6e5b2c7a91 ``` The MPS platform issues an API key, together with a [webhook signing secret](/webhooks), when you generate a test key or a live key in **Online**. Both are shown **once**: store them in your backend's vault or environment straight away. An API key acts for your merchant until it is revoked. Never put it in a browser, a mobile app or a POS front end: anything shipped to a device can be extracted from it. Let the app call your backend, and your backend call MPS. ## The API key [#the-key] ```text mps_live__ mps_test__ ``` | Part | Meaning | |---|---| | `mps_live_` / `mps_test_` | A **live key** takes real payments. A **test key** takes test payments on your own wallet: nothing is charged, booked or paid out. | | `` | 12 lower-case letters and digits. Not confidential: it is how MPS and the platform's key list refer to the key. | | `` | The confidential part. It can itself contain `_`. | Treat the whole string as one opaque value: copy it exactly, never split it or build it yourself. ## Send the key [#send-it] Send the key on **every** call in the `Authorization` header, with the `Bearer` scheme: ```http Authorization: Bearer mps_live_… ``` That is the only place it is read: not a query parameter, not an `X-Api-Key` header, not HTTP Basic. ```bash tab="curl" # Prerequisite: export MPS_API_KEY=mps_test_… and PAYMENT_REFERENCE= curl -sS --fail-with-body "https://gateway.mps-emi.com/api/payments/internet/$PAYMENT_REFERENCE" \ -H "Authorization: Bearer $MPS_API_KEY" ``` ```ts tab="TypeScript" // Prerequisite: MPS_API_KEY=mps_test_… and PAYMENT_REFERENCE in the environment. Node 18 or later. const paymentReference = process.env.PAYMENT_REFERENCE ?? ''; const res = await fetch(`https://gateway.mps-emi.com/api/payments/internet/${encodeURIComponent(paymentReference)}`, { headers: { Authorization: `Bearer ${process.env.MPS_API_KEY}` }, }); if (!res.ok) throw new Error(`Read failed: ${res.status}`); // 401: check the key; 403: the scope or the wallet console.log((await res.json()).data); ``` Both print the payment, with its `state` and `amount`. ## Test keys and live keys [#test-and-production-keys] A test key works on the same host and the same endpoints as a live key, so the only thing that changes when you go live is the key. Test payments are recognisable on their own: their payment reference starts with `test-`. See [Accept a payment › Test mode](/online-payments#test-mode). Keys are created under **Online › API keys** on the MPS platform, test and live alike, each with a name so you recognise it. You can hold several test keys at once, for example one per shop or developer. A live key can be created once the merchant it is for has signed its contract with MPS; until then test keys work as usual. API keys do not expire, test or live: a key works until you revoke it. ## Choose the merchant [#choosing-the-merchant] Every payment is for **exactly one merchant wallet**. Which one depends on the kind of key you hold: | Your key | Send `x-wallet-number`? | |---|---| | A **test key** (`mps_test_…`) | **No.** It acts for your own wallet, in test mode; a header you send is ignored. | | A **merchant key**, issued for your own wallet | **No.** It acts for that wallet; a header you send is ignored. | | A **partner key** (you take payments for merchants you onboard) | **Yes, on every call**, even while you have only one merchant: `x-wallet-number: BE0000000000`. | ```http POST https://gateway.mps-emi.com/api/payments/internet/create Authorization: Bearer mps_live_… x-wallet-number: BE0000000000 Content-Type: application/json Idempotency-Key: 4f9c2e1a-7b3d-4c8e-9a1f-0d6e5b2c7a91 ``` The wallet you name must be one of your merchants. Anything else is refused with `403` and the same message: another merchant's wallet, or one that cannot trade. A key cannot be used to discover wallets: ```json title="403 Forbidden" { "error": "invalid_request", "error_description": "The requested wallet is not covered by this key's account." } ``` Without `x-wallet-number`, a partner key names no merchant. Creating a payment then answers `403` with no body, and reading one answers `404`. An integration that still sends the header's former name, `x-card-number`, keeps working. Send one of the two: naming two different wallets answers `403` with `invalid_request`. Send the wallet number exactly as MPS shows it: upper case, no spaces, such as `BE0000000000`. Read back a payment with the same wallet it was created with: a payment created for one merchant cannot be read as another. ## Keep the key on your backend MPS shows the confidential part once and stores it hashed. It can only be replaced, never recovered. - Keep it in your backend's vault or environment, never in source control. - Never send it to a browser, an app or a POS front end, and never log it. Its `mps_live_` / `mps_test_` prefix makes a key quick to find in logs and repositories, and for leak scanners to flag. - Use a test key everywhere except production. ## Rotate a key Rotate a key, test or live, without downtime: Create a new key under **Online › API keys**. Your old key keeps working. Deploy the new key to your backend and confirm calls succeed with it. Revoke the old key on the same screen. Every key issued in the MPS platform, test or live, comes with its own webhook signing secret: deploy the new key's signing secret with it. Revoke a key at once if you think it has leaked. Revocation takes effect within about **30 seconds**; after that, every call with the key answers `401`. ## Scopes Every endpoint needs a scope: | Scope | Grants | |---|---| | `internet:create` | Create an online (card) payment | | `internet:read` | Read an online payment's status | | `payments:refund` | Refund a payment, and read and cancel its refunds. A live key holds it only on request; every test key holds it. See [Refunds](/refunds). | | `payment-links:create` | Make a payment link, and cancel one. A partner's key makes test links only. See [Create a payment link with the API](/payment-links-api). | | `payment-links:read` | List and read payment links. | | `registration-links:manage` | Make, list, read and revoke a live partner's personal registration links. Held by the live key a live partner makes for itself; a merchant's key, a partner's key for a merchant and a test key never hold it. See [Create a registration link](/registration-links). | Every key holds `internet:create` and `internet:read`. A test key also holds `payments:refund` and the payment-link scopes; a live key holds the payment-link scopes from this release on, and `payments:refund` only when MPS granted it. A live key holds it only once MPS granted it, so ask for it when you request the key. A call that needs a scope the key does not hold answers `403`. ## API key errors | Status | Code | Cause | Resolution | |---|---|---|---| | `401` | — | The key is wrong, malformed or revoked, or sent to a host other than `gateway.mps-emi.com`. The response carries `WWW-Authenticate: Bearer error="invalid_token"`. | Check the key; do not retry in a loop. See [Authentication errors](/errors-and-rate-limits#authentication-errors). | | `403` | `invalid_request` | The `x-wallet-number` you sent is not one of your merchants. Body as shown [above](#choosing-the-merchant). | Send a wallet your key covers. | | `403` | — | Create a payment with a partner key and no `x-wallet-number`. No body. A read without it answers `404`. | Send `x-wallet-number` on every call. | | `403` | — | The key is valid but lacks the endpoint's scope. No body. | See [Scopes](#scopes). | | `429` | — | Too many failed key attempts from your address (more than 10 in a minute). | Wait `Retry-After` seconds and fix the key before trying again. See [Rate limits](/errors-and-rate-limits#rate-limits). | ## Related - [Accept a payment](/online-payments) - [Errors and rate limits](/errors-and-rate-limits) - [Integration examples](/integration-examples)