Skip to content

Instantly share code, notes, and snippets.

@ansonliam
Last active August 30, 2021 03:38
Show Gist options
  • Save ansonliam/518891e017b4e2916daa35d0f5a5d5a2 to your computer and use it in GitHub Desktop.
Save ansonliam/518891e017b4e2916daa35d0f5a5d5a2 to your computer and use it in GitHub Desktop.
Shopify Hmac generation In Postman.
//This script is placed in the Pre-request Script.
// Setup two environment variables: "secret" and "hmac"
// replace the secret key from Shopify. and use {{hmac}} as the value in the header.
var secret = pm.environment.get('secret');
var body = request.data;
var hmac = CryptoJS.HmacSHA256(body, secret);
hmac = CryptoJS.enc.Base64.stringify(hmac);
console.log("body: " + body);
console.log("secret: " + secret);
console.log("hmac: " + hmac);
postman.setEnvironmentVariable("hmac", hmac);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment