Skip to content

Instantly share code, notes, and snippets.

@nCally
Created May 16, 2022 08:24
Show Gist options
  • Save nCally/508d449fb5ae8bfee62cde290850d112 to your computer and use it in GitHub Desktop.
Save nCally/508d449fb5ae8bfee62cde290850d112 to your computer and use it in GitHub Desktop.
To reduce the time to find what to do if you're new to doing pre-script
const token = pm.environment.get('token');
const accessSecret = pm.environment.get('accessSecret');
// i don't know if the next line works for query params yet
const body = JSON.parse(pm.request.body.raw);
let sigPayload = '';
for (item in body) {
sigPayload += item + "=" + body[item] + "&";
}
const text = sigPayload + "api-key="+token+"&api-secret="+accessSecret;
const hash = CryptoJS.HmacSHA256(text, accessSecret);
const hashBase64 = CryptoJS.enc.Base64.stringify(hash);
pm.environment.set("hmac", hashBase64);
pm.environment.set("token", token);
pm.environment.set("timestamp", Date.now());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment