Making custom API requests via Postman's pre-request script feature

Today I came across an API I needed to work with which required me to place custom request headers to make authenticated requests. The content of the headers required some custom logic to generate. In this case it required me to create a string representation of the current UTC date and time in HTTP format (RFC2616 format) e.g 12 Feb 2011 20:59:04 GMT then use that to calculate the hexadecimal HMAC SHA1 hash of that string using your secret key (supplied) as the hash key.

Lucky for me, I learnt that I was able to dynamically inject variables into the request headers using a feature by Postman called Pre-request Scripts. This feature allows you to set Postman variables just before a request is being made. Postman also kindly included CryptoJS (along with Lodash, cherio, SugarJS and more) in the Postman Sandbox

postman.setGlobalVariable("hmacComputed", CryptoJS.HmacSHA1(<some msg>, <some secret>));
postman.setGlobalVariable("someKey1","someValue2" );

p27

p28

comments powered by Disqus