Skip to main content

Using Postman with our API

Prerequisites

Before you start, make sure that you have:

  • Changelly API keys
  • A Postman account

1. Get jsrsasign library used for signing

  1. Create a new GET request.
  2. Copy https://raw.githubusercontent.com/kjur/jsrsasign/master/jsrsasign-all-min.js to the URL field.
  3. Go to the Scripts tab, select Post-response section and enter::
    postman.setGlobalVariable("jsrsasign-js", responseBody);
  4. Send the request.
note

This step is essential for sending authorized requests to our API. Once completed, the outcome of the GET request is stored in a global variable, which is subsequently employed in the pre-request scripts used for authorization.

2. Add a pre-request script

  1. Create a new POST request.
  2. Go to the Pre-request Script tab.
  3. Insert the following script and replace the placeholders (yourPrivateKey, yourApiKey) with your actual keys:
    const navigator = {}; //fake a navigator object for the lib
    const window = {}; //fake a window object for the lib
    eval(postman.getGlobalVariable("jsrsasign-js"));

    const privateKeyString = 'yourPrivateKey';

    const key = new RSAKey();
    key.readPKCS8PrvKeyHex(privateKeyString);

    const sig = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
    sig.init(key);
    const signature = hextob64(sig.signString(pm.request.body.raw));

    pm.request.headers.add({
    key: 'x-api-key',
    value: 'yourApiKey'
    });

    pm.request.headers.add({
    key: 'x-api-signature',
    value: signature
    });

    postman.setEnvironmentVariable('x-api-key', 'yourApiKey')
    postman.setEnvironmentVariable('x-api-signature', signature)
  4. Set the API URL in the URL field and specify the body data in the Body tab using the raw mode.
  5. Send the request to make sure that Postman is now able to send requests to our API.