I wanted to know: How can I get the current timestamp for UTC in ISO 8601 format to appear in the body data of a Postman request?
After reading some of the Postman documentation and online comments, this is the solution (using Postman v5.0.1 for Chrome 58.0.3029.110 on macOS 10.12.5) I used:
-
In the Builder, while editing a request, click the "Pre-request Script" heading below the URL field.
-
In the editor field that appears, enter this single line of JavaScript:
postman.setGlobalVariable('timestampUtcIso8601', (new Date()).toISOString());
-
Click the "Body" heading below the URL field.
-
In the editor field that appears, wherever you want the newly formatted timestamp to appear, add the reference
{{timestampUtcIso8601}}
.💡 Remember: Don't use a dollar sign (
$
) in this variable reference. That's only needed for reserved system variables automatically set by Postman. E.g., the system timestamp (the number of seconds since 00:00:00 UTC, 1 Jan 1970),{{$timestamp}}
.
How this works is Postman runs the "Pre-request Script" before each request, which updates the timestampUtcIso8601
global variable with the current time. When the request references the variable, it will be replaced with its most recent value.
As others who had a similar question have written, it can be repetitive to add this "Pre-request Script" to every request that needs the timestamp. It would be helpful if Postman supported this kind of script at the collection (folder) level. Maybe even better would be for it to support JavaScript when setting values for environment and global variables.
Fortunately, it seems that once the variable has been set, it will remain available for other requests that follow it. They can use the previously-set value without updating it, but it will be getting further in the past.
Hi Could you please let me know how to get delayed timestamp? per1 hour or 2 hour pirior to the sys date?
my request is like below
url?starttime=2017-10-25T12:00&endtime=2017-10-25T13:00 also this is fine(end time = sysdate) rite now i am doing manually want to do it dynamically
http://host.php?timestamp=2017-10-24T13:00&endTimestamp={{timestampUtcIso8601}}