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
- Create a new
GET
request. - Copy https://raw.githubusercontent.com/kjur/jsrsasign/master/jsrsasign-all-min.js to the URL field.
- Go to the Scripts tab, select Post-response section and enter::
postman.setGlobalVariable("jsrsasign-js", responseBody);
- 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
- Create a new
POST
request. - Go to the Pre-request Script tab.
- 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) - Set the API URL in the URL field and specify the body data in the Body tab using the raw mode.
- Send the request to make sure that Postman is now able to send requests to our API.