Skip to main content

Using Postman with our API

Before you start, make sure that you have:

  1. Changelly API keys
  2. 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);
  1. 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 Scripts 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 API_PUBLIC_KEY = 'yourApiKey';
const API_PRIVATE_KEY = 'yourPrivateKey';

const URL = request.url.toString();
const message = pm.request.body.raw ? JSON.parse(pm.request.body.raw) : {};
const payload = URL + JSON.stringify(message);

const privateKeyString = Buffer.from(API_PRIVATE_KEY, 'base64').toString('binary');
const private_key_object = KEYUTIL.getKey(privateKeyString);
const sig = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
sig.init(private_key_object);

const signature = hextob64(sig.signString(payload));

pm.request.headers.add({
key: 'X-Api-Key',
value: API_PUBLIC_KEY
});

pm.request.headers.add({
key: 'X-Api-Signature',
value: signature
});
  1. Set the API URL in the URL field and specify the body data in the Body tab using the raw mode.
  2. Send the request to make sure that Postman is now able to send requests to our API.