Escape or Ignore Postman Variables

Viewed 794

I'm trying to send the following (literal) text in a request body in Postman:

{
  "message": "Hi {{USERNAME}} your code is {{CODE}}"
}

However, in my Postman environment I have a USERNAME variable, so Postman is substituting in the variable value and the following hits my backend (note that I don't have a CODE variable in Postman):

{
  "message": "Hi username_value_in_postman your code is {{CODE}}"
}

So I'm looking for a way to escape or ignore the Postman variable syntax so that it sends the literal string. I've searched the docs and SO, but didn't find anything useful for my problem, so any help would be appreciated.

1 Answers

Escaping doesn't seem to work, so I guess you'd either need to rename your variable(s) or use Pre-request and Tests scripts:

In Pre-resuqest script, you can write this code:

pm.variables.set('usernameBackup', pm.variables.get('USERNAME'));
pm.environment.unset('USERNAME');

And you set the environment variable again in the Tests script:

pm.environment.set('USERNAME', pm.variables.get('usernameBackup'));
pm.variables.unset('usernameBackup');
Related