Sam
Sam

Reputation: 405

Postman: How to use environment variables in Request Body

I am trying to replace the value of JSON Body in the Postman from environment variable, and the value is actually replaced but it converts the JSON into a string when passed to the POST request so the request eventually fails since the POST request expects JSON body..

For example, Here is the below request and the variables are already declared with values in the Postman

Screenshot of Postman Body

And once the request is sent, the entire body is converted to String. Any idea how to keep the body is JSON even after substituting the value for the variable and not let it convert to String?

enter image description here

Upvotes: 20

Views: 18997

Answers (1)

Mudzia Hutama
Mudzia Hutama

Reputation: 504

Example, I have environment variable : variable name = port, initial value = 4242, current value = 4242. variable name = name, initial value = abcd, current value = abcd. To use environment variable as request body, use this in request body:

{
 "string": "{{name}}",
 "number": {{port}}
}

Upvotes: 23

Related Questions