Step 2: Postman
1. Fork Banxa Sandbox Collection
Use Banxa API collection in Postman by accessing the read-only Banxa Workspace and forking the Collection to your personal or company Workspace.
Link to Banxa Workspace: https://www.postman.com/crimson-comet-2961/workspace/banxa-api-sandbox/collection/19155430-c6f45571-964c-4ac9-8b01-8b08b1bc3806?action=share&creator=19155430
![Postman Fork Collection.png 747](https://files.readme.io/45607fe-Postman_Fork_Collection.png)
2. Configure credentials
Configure your authorization credentials and domain. Click Save.
Make sure that "https://" is included in front of the domain that you have been provided. e.g. https://binance.banxa.com
![Configure credentials and domain.png 1920](https://files.readme.io/6016484-Configure_credentials_and_domain.png)
3. Start invoking the APIs using your credentials
Ensure that the Banxa API Sandbox environment is selected so that environment variables are applied to each request.
![Environment Selection.png 1438](https://files.readme.io/af2bfcb-Environment_Selection.png)
Troubleshooting
If you are getting an unauthorized error message when running an API call, double the following things:
- The domain configured in your Environments variables include a "https://" in front of the URL e.g. https://binance.banxa.com
- Ensure that the Header variables of your API call includes Authorization and a Value is generated
![Postman Authorization.png 1218](https://files.readme.io/544bdae-Postman_Authorization.png)
- The Collection level Authorization Type is Bearer Token, and the Token is HMAC. The Folders and API calls should inherit Authorization settings from the parent.
![Postman Authorization.png 1218](https://files.readme.io/c5ff44a-Postman_Authorization.png)
- Double check that the Pre-request Script at the Collection level is as per below
![Postman Pre-request Script.png 896](https://files.readme.io/7b804fc-Postman_Pre-request_Script.png)
var CLIENT_KEY = pm.environment.get("key");
var SECRET_KEY = pm.environment.get("secret");
var AUTH_TYPE = 'HMAC-SHA512';
var AUTH_VERSION = '5.1.2';
function epochTime() {
var d = new Date();
var t = d.getTime();
var o = t + "";
return o.substring(0, 10);
}
var timestamp = epochTime();
function getAuthHeader(httpMethod, requestUrl, requestBody) {
var requestPath = pm.request.url.getPath();
var requestData;
if (httpMethod=="GET"){
requestPath = pm.request.url.getPathWithQuery();
requestPath = replaceVariablesWithValues(requestPath);
requestData = [httpMethod, requestPath, timestamp].join("\n");
} else {
requestPath = replaceVariablesWithValues(requestPath);
requestBody = replaceVariablesWithValues(requestBody);
body = JSON.stringify(JSON.parse(requestBody));
requestData = [httpMethod, requestPath, timestamp, body].join("\n");
}
console.log(requestData);
return CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(requestData, SECRET_KEY));
}
function replaceVariablesWithValues(str) {
var env = pm.environment.toObject();
for (var p in env) {
if( env.hasOwnProperty(p) ) {
str = str.replace('{{' + p + '}}', env[p])
}
}
return str;
}
console.log(request['headers']);
signature = getAuthHeader(request['method'], request['url'], request['data']);
postman.setEnvironmentVariable('hmac', CLIENT_KEY + ":" + signature + ":" + timestamp );
Updated over 1 year ago