Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (40 sloc) 2.1 KB

Generating signed HMAC request using Postman

Download Postman

Download and install Postman: https://www.getpostman.com/

Postman Environment Setup

You have to set up an environment in Postman for setting variables needed in each request. Top-right of the postman window, you can create a new environment.

alt text

Setup Pre-request Script

You will need to insert your key/secret. Start a new request, and add this Pre-request Script:

postman.clearEnvironmentVariable("x-prd-time");
postman.clearEnvironmentVariable("x-prd-key");
postman.clearEnvironmentVariable("x-prd-signature");
postman.clearEnvironmentVariable("x-prd-nonce");

api_key = 'API_KEY';
api_secret = 'API_SECRET';
api_method = request.method;
nonce = Math.random().toString(36).substr(2, 16);
current_time = Math.floor(Date.now() / 1000);

payload = '{"method":\"' + api_method + '\","x-prd-key":\"' + api_key + '\","x-prd-nonce":\"' + nonce + '\","x-prd-time":\"' + current_time + '\"}';
console.log("Using payload as " + payload);

var sha256digest = CryptoJS.HmacSHA256(payload, api_secret);
var base64sha1 = CryptoJS.enc.Base64.stringify(sha256digest);

postman.setEnvironmentVariable('x-prd-signature', base64sha1);
postman.setEnvironmentVariable('x-prd-key', api_key);
postman.setEnvironmentVariable("x-prd-time", current_time);
postman.setEnvironmentVariable("x-prd-nonce", nonce);

Setup Request Headers

These are the headers that will be passed with your request, after the pre-request script has populated them.

alt text

Testing and Debugging

Now issue a GET request to https://api.predikto.io/whoami

You may get an empty response, but it should be a HTTP 200.

If you want to see console output in Postman, follow:

  • Type chrome://flags inside your Chrome URL window
  • Search for "packed" or try to find the "Enable debugging for packed apps" setting
  • Enable the setting
  • Restart Chrome
  • Right click in Postman and go to Inspect.
  • You should see script output in console now.