Skip to content

Instantly share code, notes, and snippets.

@achinta
Last active April 22, 2022 16:41
Show Gist options
  • Save achinta/85e5c387c68acda4358ace99d9dcf8d2 to your computer and use it in GitHub Desktop.
Save achinta/85e5c387c68acda4358ace99d9dcf8d2 to your computer and use it in GitHub Desktop.
Postman Snippets - creating variables in pre-request script
// create random variable with timestamp as suffix
var ts = pm.variables.replaceIn("{{$timestamp}}");
pm.collectionVariables.set("name_ts", 'test ' + ts);
//create timestamp variables
var moment = require('moment');
pm.collectionVariables.set('arrival_date', moment().format(("YYYY-MM-DD HH:mm:ss")));
pm.collectionVariables.set('departure_date', moment().add(5, 'days').format(("YYYY-MM-DD HH:mm:ss")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment