# Set up Postman

:::note[Third-party product]
Postman is a third-party product not owned by Revolut.
This guide is provided for convenience only, and Revolut doesn't guarantee that the Postman features described will continue to work in the same way or at all.
For detailed instructions, see the [Postman documentation](https://learning.postman.com/).
:::

Postman is one of the industry-standard tools for testing APIs.
To make testing easier, Revolut provides Postman collections for the [Business](/docs/api/business) and [Merchant](/docs/api/merchant) APIs.

This guide explains how to configure a collection with Bearer Token auth and an optional pre-request script that handles request signing automatically, so you don't need to generate signatures for each request.
You can either import a Revolut collection or [create your own](https://learning.postman.com/docs/use/use-collections/create-collections) from the [Revolut API schemas](https://github.com/revolut-engineering/revolut-openapi).

For security reasons, [use a dedicated API key for testing](#tips-and-troubleshooting) instead of your Production key.

## How it works

Postman signs each request automatically using a pre-request script attached to your collection.
The script reads your private key from an environment variable, constructs the signing message, generates the signature, and injects the `Revolut-Api-Timestamp` and `Revolut-Api-Signature` headers.

For API keys [without signing](/docs/guides/api-console/signing-requirements), you only need Bearer Token auth – no script required.

## Before you begin

Before you start, make sure you have:

- An API key created in the [API Console](https://developer.revolut.com/console).
  If you don't have one yet, see [Create an API key](/docs/guides/api-console/create-key).
- [Postman](https://www.postman.com/downloads/) installed.
- If your API key has signing enabled: your `private.pem` file saved on your machine.
- A [Revolut Postman collection](https://www.postman.com/revolut-api/revolut-developers/overview) added to your Postman client.

## Set up Postman

### 1. Create an environment

[Create a new Postman environment](https://learning.postman.com/docs/use/send-requests/variables/managing-environments) with the following variables.
The `url` value depends on which endpoints you're calling and whether you're using Sandbox or Production.
If you use both the Business and Merchant endpoints, create separate environments for each.

- ![$Business endpoints]
  | Variable | Type | Value |
  |---|---|---|
  | `url` | `default` | <ul><li>Sandbox: `https://sandbox-b2b.revolut.com`</li><li>Production: `https://b2b.revolut.com`</li></ul> |
  | `api_key` | `secret` | Your API key copied from the API Console. |
  | `private_key` | `secret` | Required only if you've added a signing key. The entire contents of your `private.pem` file, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. Do not add any new lines. |

- ![$Merchant endpoints]
  | Variable | Type | Value |
  |---|---|---|
  | `url` | `default` | <ul><li>Sandbox: `https://sandbox-merchant.revolut.com`</li><li>Production: `https://merchant.revolut.com`</li></ul> |
  | `api_key` | `secret` | Your API key copied from the API Console. |
  | `private_key` | `secret` | Required only if you've added a signing key. The entire contents of your `private.pem` file, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. Do not add any new lines. |

<!-- TODO: Re-add Crypto Exchange and Crypto Ramp env tabs when Crypto migration is complete
- ![$Crypto Exchange endpoints]
  | Variable | Type | Value |
  |---|---|---|
  | `url` | `default` | `https://revx.revolut.com` |
  | `api_key` | `secret` | Your API key copied from the API Console. |
  | `private_key` | `secret` | The entire contents of your `private.pem` file, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. Do not add any new lines. |

- ![$Crypto Ramp endpoints]
  | Variable | Type | Value |
  |---|---|---|
  | `url` | `default` | `https://ramp-partners.revolut.com` |
  | `api_key` | `secret` | Your API key copied from the API Console. |
  | `private_key` | `secret` | The entire contents of your `private.pem` file, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. Do not add any new lines. |
-->

If you don't have auto-save enabled, click **Save**.

### 2. Set up authentication

1. Open your Postman collection [settings](https://learning.postman.com/docs/use/use-collections/create-collections#configure-a-collection).
2. In the **Authorization** tab, set the **Auth Type** to **Bearer Token** and set the token to `{{api_key}}`.
3. For each endpoint in your collection, in the **Authorization** tab, make sure that it inherits the Bearer Token from the parent collection. See the [Postman documentation](https://learning.postman.com/docs/use/send-requests/authorization/specifying-authorization-details#inherit-authorization) for more details.

### 3. Add the signing script

Whether you need request signing depends on your API key, not on the endpoints you call — see [Signing requirements](/docs/guides/api-console/signing-requirements).

If your API key has a signing key attached, [add a pre-request script](https://learning.postman.com/docs/tests-and-scripts/write-scripts/pre-request-scripts/#reuse-pre-request-scripts) to your collection as follows.

:::tip
- The script only signs requests when a `private_key` variable is present, so you can add it regardless of your key type.
- The script reads the variables with `pm.variables.get()`, so it resolves them from any scope – environment, collection, or global.
- If a variable is defined in multiple scopes, the environment value takes precedence.
- The same collection works with both signing and non-signing keys.
:::

In the **Scripts** tab, select **Before request** (or **Pre-request**, depending on your version) and paste the following script:

```javascript [Postman pre-request script]
function interpolate(value) {
    const { Property } = require('postman-collection');
    return Property.replaceSubstitutions(value, pm.variables.toObject());
}

async function signEd25519(message, pemPrivateKey) {
    const pemContents = pemPrivateKey
        .replace(/-----BEGIN PRIVATE KEY-----/g, '')
        .replace(/-----END PRIVATE KEY-----/g, '')
        .replace(/\\n/g, '')
        .replace(/\s+/g, '');

    const binaryDerString = atob(pemContents);
    const binaryDer = new Uint8Array(binaryDerString.length);
    for (let i = 0; i < binaryDerString.length; i++) {
        binaryDer[i] = binaryDerString.charCodeAt(i);
    }

    const importedKey = await crypto.subtle.importKey(
        "pkcs8",
        binaryDer.buffer,
        { name: "Ed25519" },
        false,
        ["sign"]
    );

    const signatureBuffer = await crypto.subtle.sign(
        { name: "Ed25519" },
        importedKey,
        new TextEncoder().encode(message)
    );

    return btoa(String.fromCharCode(...new Uint8Array(signatureBuffer)));
}

const apiKey = pm.variables.get("api_key")?.trim();
const privateKey = pm.variables.get("private_key")?.trim();

if (apiKey && privateKey) {
    const timestamp = Date.now().toString();
    const method = pm.request.method.toUpperCase();

    const url = new URL(interpolate(pm.request.url.toString()));
    const path = url.pathname || "/";
    const query = url.searchParams.toString();

    let body = "";
    if (method !== "GET" && pm.request.body && pm.request.body.raw) {
        const rawBody = interpolate(pm.request.body.raw);
        try {
            body = JSON.stringify(JSON.parse(rawBody));
        } catch {
            body = rawBody;
        }
    }

    const message = timestamp + method + path + query + body;
    const signature = await signEd25519(message, privateKey);

    // Override the URL and body so the values sent match the values signed
    pm.request.url.update(url.origin + path + (query ? "?" + query : ""));
    if (body) {
        pm.request.body.update({
            mode: "raw",
            raw: body,
            options: { raw: { language: "json" } }
        });
    }

    pm.request.headers.upsert({ key: "Revolut-Api-Timestamp", value: timestamp });
    pm.request.headers.upsert({ key: "Revolut-Api-Signature", value: signature });
}
```

If you don't have auto-save enabled, click **Save**.

:::tip
You're all set! Your collection is now configured to make authenticated requests to the Revolut API.
:::

## Tips and troubleshooting

:::warning[Use a dedicated test key]
For security reasons, use a dedicated API key for testing in Postman instead of your Production API key.
If your Postman environment is shared or compromised, the `private_key` variable can be extracted and used to sign requests on your behalf.
:::

:::warning[Don't add auth headers on individual endpoints]
Make sure that individual endpoints inherit the Bearer Token from the parent collection instead of overriding it.
See the [Postman documentation](https://learning.postman.com/docs/use/send-requests/authorization/specifying-authorization-details#inherit-authorization) for more details.
The collection-level Bearer Token auth handles the `Authorization` header automatically.
If you're using the signing script, it also handles the `Revolut-Api-Timestamp` and `Revolut-Api-Signature` headers.
Overriding auth settings on individual endpoints can cause authentication errors.
:::

:::tip[Save after pasting the script]
Newer Postman versions [save changes automatically](https://blog.postman.com/engineering/a-simpler-and-local-first-variables-experience), but in older versions, changes must be saved manually.
If your Postman doesn't auto-save, make sure to save after pasting the script — unsaved settings show an orange dot on the tab next to the collection name, and unsaved changes are not applied.
:::

:::tip[Request body formatting]
When using `POST` or `PUT` requests, format the body as **raw JSON**.
Avoid adding code comments (`//` or `/* */`) in the request body – they break JSON parsing.
The script automatically minifies the body before signing, so the signature matches the actual payload sent.
:::

## What's next

- [Manage API key settings](/docs/guides/api-console/manage-key-permissions): Update key permissions, configure IP allowlisting, and manage signing keys.
- [Rotate an API key](/docs/guides/api-console/rotate-api-key): Replace an API key without downtime.
- See the API reference for:
    - [Merchant endpoints](/docs/api/merchant)
    - [Business endpoints](/docs/api/business)