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:
- mobile - +639012345678
- value - 100
- merchantId - TEST_MERCHANT1
- referenceNumber - TEST_MERCHANT1-000001
- authCode - 000001
- secretKey - a2c36909-c9cc-4ed3-9423-ec170e1eb6c2