Skip to content

Commit 0e12b0a

Browse files
author
Dave Wong
committed
updated pre-request script
1 parent 9cd2547 commit 0e12b0a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

readme.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,30 @@ function guid() {
8787
s4() + '-' + s4() + s4() + s4();
8888
}
8989

90+
function getTimestamp() {
91+
var date = (new Date()).toISOString();
92+
date = date.split("T");
93+
date[1] = date[1].split(".")[0];
94+
return date.join(' ');
95+
}
96+
9097
postman.setEnvironmentVariable("x-signed-id", guid());
91-
postman.setEnvironmentVariable("x-signed-timestamp", (new Date()).toUTCString());
98+
postman.setEnvironmentVariable("x-signed-timestamp", getTimestamp());
9299
postman.setEnvironmentVariable("x-algorithm", "sha256");
93100

94101
var payload = {
95102
"id": postman.getEnvironmentVariable("x-signed-id"),
96103
"method": request.method,
97104
"timestamp": postman.getEnvironmentVariable("x-signed-timestamp"),
98105
"uri": request.url.replace("{{url}}", postman.getEnvironmentVariable("url")),
99-
"content": (Object.keys(request.data).length === 0) ? "" : request.data
106+
"content": (Object.keys(request.data).length === 0) ? "" : JSON.stringify(JSON.parse(request.data))
100107
};
101108

102109
var hash = CryptoJS.HmacSHA256(JSON.stringify(payload), postman.getEnvironmentVariable("key"));
103110
var signature = hash.toString();
104111

105112
postman.setEnvironmentVariable("x-signature", signature);
113+
106114
```
107115

108116
Note for this to work you'll have to setup your environment to have the following variables:

0 commit comments

Comments
 (0)