Skip to content

Instantly share code, notes, and snippets.

@aggieben
Created April 13, 2018 16:45
Show Gist options
  • Save aggieben/a765d4828df00c8561b2b36e1a4f65b1 to your computer and use it in GitHub Desktop.
Save aggieben/a765d4828df00c8561b2b36e1a4f65b1 to your computer and use it in GitHub Desktop.
Postman Pre-Request Script Variable Substitution
function replaceVariables(templateString) {
let tokens = _.uniq(templateString.match(/{{\w*}}/g))
_.forEach(tokens, t => {
let variable = t.replace(/[{}]/g, '')
let value = environment[variable] || globals[variable]
templateString = templateString.replace(new RegExp(t,'g'), value)
});
return templateString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment