Escape curly braces but inject a variable in it

I have a somewhat unique situation. The API I’m testing takes {{ as part of the json body and uses it as a sort of macro.

I’d like to inject a variable into this macro, it looks like this without variables injected:

    "key": "Some text: {{DATE(2020-10-10T00:00:00.000Z),long}} some more text"

I’d like to be able to replace that date string with a Postman variable:

    "key": "Some text: {{DATE({{$TODAY}}),long}} some more text"

But it just sends the whole block of braces and doesn’t replace that date. Is there a way to escape the first curly braces or otherwise use a different technique to inject the variable?

Hello @Kikketer,

Happy to have you as part of this Community :bouquet:

So based on the snippets you have provided below, seems like the variable “TODAY” is a environment variable. If that’s the case the dollar is not required. We need to provide the $ for Dynamic variable like “$randomDateFuture”.

So if you have already defined the variable “TODAY” just access like below

    "key": "Some text: {{DATE({{TODAY}}),long}} some more text"

Else if you haven’t defined value for the variable, please try adding the below snippet to your Pre-request script section:

var moment = require('moment');

pm.environment.set('TODAY', moment().format(("YYYY-MM-DD")));

and access the variable “TODAY” as same.

I hope this helps :slightly_smiling_face:

1 Like