Postman – Including the Header Date

I have found Postman to be a very useful tool for testing Web Api’s, but according to Postman’s documentation, sending certain restricted headers can be an issue. Using Postman Interceptor allows you to overcome this restriction but I came across one problem when setting the restricted Date header.

I had been using the Pre-requests scripts to set the Date dynamically using environment variables, again following the documentation. However, each time I submitted the request my Date header was coming through as null. The problem turned out to be the date format as this needs to be in GMT format and fortunately the fix turned out to be relatively simple.

Javascript has a toGMTString() method that works but the method is being deprecated so the toUTCString() works just as well so the environment variable becomes

postman.setEnvironmentVariable('timestampHeader',new Date().toUTCString());
Advertisements