Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variables from JSON to postman body

I want to parameterized my tests in Postman. This is the example body of POST request:

{
  "entity_id": "{{entity_id}}",
  "text": data.comment_name
}

entity_id is global variable and it works correctly, but I want to set value of text from JSON file. data.comment_name doesn't work it saved me exactly data.comment_name as text variable. I want to include this JSON file with all variables in collection runner. How can I do that?

like image 969
robmax Avatar asked Jan 09 '18 08:01

robmax


People also ask

How do you pass parameters in body Postman?

To send a query parameter, add it directly to the URL or open Params and enter the name and value. When you enter your query parameters in either the URL or the Params fields, these values will update everywhere they're used in Postman.


1 Answers

If your data file looks something like this JSON example:

[
    {
        "entity_id": 1,
        "comment_name": "This is my comment_name"
    }
]

To reference the values in the file, the POST body needs to look like this:

Postman Body

This is how your example would be but you don't need to add the " " around the variable. This could cause issues if the value is a number and adding the quotes around the value in the request body, would make this a string and possibly lead to a bad request.

like image 196
Danny Dainton Avatar answered Oct 06 '22 14:10

Danny Dainton