Skip to content

Instantly share code, notes, and snippets.

@nCally
Created May 16, 2022
Embed
What would you like to do?
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