Postman - How to pass a global variable into JSON body


Json Problem Overview

I'm working with Postman right now and I have to do a lot of requests, and in the body I'm passing a JSON content. I would like to know if is there a way to pass the value of a global variable into JSON body. Thank you.

Json Solutions

Solution 1 - Json

If using a raw JSON body:

    "test key":"{{global variable}}"

On sending the request, the curly braces will be replaced with the value of the variable.

Solution 2 - Json

I think what you want to do is described here.

> To use a variable you need to enclose the variable name with double curly braces – {{my_variable_name}}.

Solution 3 - Json

Double curly bracket is working in header parameter, url or inside JSON body. Inside tests you should use globals example: {"url": globals.url} or {"url": globals["url"]}

Solution 4 - Json

You can pass

   "productId": {{**ProductID**}},
   "quantity": 1

Where ProductID is your global variable name
in raw format JSON (application/json)

Solution 5 - Json

Yep, double curly brackets is the way to go to achieve this - make sure you have the latest version of Postman (though if you are still running 2014 code when this feature was introduced, shame on you!)


    "variable": "{{value}}"

See the second paragraph here in the Variables section of the documentation - it specifically mentions the request body.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan PascheviciView Question on Stackoverflow
Solution 1 - JsonRadamHusseinView Answer on Stackoverflow
Solution 2 - JsonPhilipp StaussView Answer on Stackoverflow
Solution 3 - JsonbartpieView Answer on Stackoverflow
Solution 4 - JsonShailendraView Answer on Stackoverflow
Solution 5 - JsonKolonUKView Answer on Stackoverflow