Send API requests with Postman
This instruction helps you send requests to Exchange API using Postman.
Step 0: Сheck prerequisites
Before Postman setting, ensure you have:
- Generated Cripto InterCambio API keys.
- A Postman account.
Step 1: Set authorized requests
To set authorized requests, follow these steps:
- Create a new
GETrequest. - Copy jsrsasign-all-min.js code to the URL field.
- Send the request.
- Go to the Tests tab and insert the code:
postman.setGlobalVariable("jsrsasign-js", responseBody);
info
Step 1 is crucial for sending authorized requests to Exchange API. After completion, a global variable stores the GET request outcome. This variable subsequently employes in the pre-request scripts for authorization.
Step 2: Add a pre-request script
After setting authorized requests, follow these steps to add a pre-request script:
- Create a new
POSTrequest. - Go to the Pre-request Script tab.
- Insert the following script with your actual keys instead of the
yourPrivateKeyandyourPublicApiKeyBase64placeholders:
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.environment.get("yourPrivateKey");
const publicKeyBase64String = pm.environment.get("yourPublicApiKeyBase64");
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: publicKeyBase64String
});
pm.request.headers.add({
key: 'x-api-signature',
value: signature
});
pm.environment.set('x-api-key', publicKeyBase64String);
pm.environment.set('x-api-signature', signature);
- Set the API URL in the URL field.
- Specify the body data in the Body tab using the raw mode.
- Send the request to make sure Postman can proceed requests to Exchange API.