Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

Escape or Ignore Postman Variables

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...