It's often handy to pass request parameters dynamically, rather than hard-code them. For example, imagine you're setting up a request to POST to a /appointments
endpoint, which expects a appointmentDate
to be passed in.
You could set appointmentDate=2021-11-19
in the request body itself, but it might be better to define it relative to the current date so you don't have to go in and modify it next time you run it, to make sure it's not in the past!.
To create an appointmentDate
that's always 2 days from now, you can create a pre-request script:
var moment = require('moment');
pm.environment.set('appointmentDate', moment().add(2, 'days')
.format(("YYYY-MM-DD")));
...and then use the {{appointmentDate}}
variable in your request.
Hope that helps!