I'm getting "TypeError: Cannot read property 'sigBytes' of undefined" error when running a postman collection with a cryptojs pre-request script. The pre-request script computes a hmac-sha256 signature which is also part of parameters of the main API to be called.
Below is my script:
let mobile = pm.environment.get('mobileNumber');
let value = pm.environment.get('value');
let merchantId = pm.environment.get('merchantId');
let referenceNumber = pm.environment.get('referenceNumber');
let authCode = pm.environment.get('authCode');
let secretKey = pm.environment.get('secretKey');
let string = mobile + value + merchantId + referenceNumber + authCode;
pm.environment.set('string', string);
let hmac = CryptoJS.HmacSHA256(string, secretKey);
pm.environment.set('hmac', hmac);
signature = "hmac256-" + hmac;
pm.environment.set('signature', signature);
I already tried encoding the string and secretKey to UTF-8, base64stringify, JSON stringify but I'm getting errors still.
Here are sample values from each of the variables:
Looks like at least one of your environment variables isn't defined.
The error message is due to a bug in CryptoJS: https://github.com/brix/crypto-js/issues/85
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With