In Postman, the dynamic variable {{$timestamp}} inserts the current Unix Time Stamp into a request. (Represented as the number of seconds since January 1, 1970)
"currentTime": "1510934784" However, the API I am working with expects timestamps formatted as MM/DD/YYYY.
"currentDate": "11/17/2017" How do I insert the current date (formatted as MM/DD/YYYY) into my request with Postman?
Instead use a conditional GET request. This will also tell you that the timestamp to pass to the service will need to be in a format specified in Date and Time Specification section of RFC 2822. Show activity on this post. I like the idea of passing the number of seconds since 1970.
In Postman, the dynamic variable {{$timestamp}} inserts the current Unix Time Stamp into a request. ( Represented as the number of seconds since January 1, 1970) "currentTime": "1510934784"
You could use moment.js with Postman to give you that timestamp format.
You can add this to the pre-request script:
const moment = require('moment'); pm.globals.set("today", moment().format("MM/DD/YYYY")); Then reference {{today}} where ever you need it.
If you add this to the Collection Level Pre-request Script, it will be run for each request in the Collection. Rather than needing to add it to all the requests individually.
For more information about using moment in Postman, I wrote a short blog post: https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/
Use Pre-request script tab to write javascript to get and save the date into a variable:
const dateNow= new Date(); pm.environment.set('currentDate', dateNow.toISOString()); and then use it in the request body as follows:
"currentDate": "{{currentDate}}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With