Use Postman with our API
Prerequisites
Before you start, make sure that you have:
- Changelly API keys
- A Postman account
To improve your UX with our API, you can download the Postman collection, extract it, and import it into your Postman account.
The collection already contains all the variables at the collection scope and the pre-request script at the request scope.
Download the Postman collection (.zip)
1. Get jsrsasign library used for signing
- Create a new Postman collection or select the imported Changelly API Reference collection.
- Create a new
GETrequest. - Set the URL
https://raw.githubusercontent.com/kjur/jsrsasign/master/jsrsasign-all-min.jsin the URL field. - Go to the Scripts tab, select the Post-response section, and paste the code:
pm.environment.set("jsrsasign-js", responseBody);
- Send the request.
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.
Perform this step only once before sending requests.
2. Set up keys
- Go to the Variables tab at the collection scope.
- Set your private key and API Key in Base64 as variable values.
3. Set sending requests
If you want to set sending requests with the imported Postman collection, follow these steps:
- Choose the necessary request from the Postman collection.
- Specify the request parameter values in the Body tab.
- Send the request.
If you want to set sending requests manually, follow the steps from the below section:
How to set sending requsts manually
- Create a new
POSTrequest. - Go to the Pre-request Script tab.
- Insert the following script:
const navigator = {}; //fake a navigator object for the lib
const window = {}; //fake a window object for the lib
eval(pm.globals.get("jsrsasign-js"));
const privateKeyString = pm.variables.get("privateKey");
const ApiKeyBase64String = pm.variables.get("ApiKeyBase64");
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: ApiKeyBase64String
});
pm.request.headers.add({
key: 'x-api-signature',
value: signature
});
pm.environment.set('x-api-key', ApiKeyBase64String);
pm.environment.set('x-api-signature', signature);
- Set the API URL
https://api.changelly.com/v2in the URL field. - 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.