Open up Postman and go to the Pre-request Script tab.
Below is the skeleton that needs to be pasted into it if you don’t want to use the attached file:
const crypto = require('crypto-js');
const secret = ‘my-secret';
const body = {
"event": "envelope-completed",
"data": {
"envelopeId": "2b6a9e15-b8ca-43f3-9e7b-e505504560ed",
"envelopeSummary": {
"envelopeDocuments": [
{
"documentIdGuid": "cbf2d203-12fd-4f93-9eb9-1e7e738e8206",
"PDFBytes": "",
"documentFields": [
{
"name": "DocumentRequestId",
"value": "1"
}
]
},
{
"documentIdGuid": "090fe7f3-33ab-4ad9-b98a-d9d554616a1a",
"PDFBytes": ""
}
]
}
}
};
const jsonString = JSON.stringify(body);
const hmac = crypto.HmacSHA256(jsonString, secret);
const signature = crypto.enc.Base64.stringify(hmac);
// Set environment variables
pm.environment.set("calculated_signature", signature);
pm.environment.set("request_body", jsonString);