Need help in passing variable in body

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
i have designed pre-requisite script as show below to generate random name field values
let x = Math.random();
let name = ‘Lauren’ + x;
pm.globals.set(“name” ,name);

how can i pass this name variable in below body format
{“parameterData”: “{"action": "Insert","name": "Lauren"}”}

Details (like screenshots):

How I found the problem:

I’ve already tried:

Hi @rekha135

You would just call it like you would a normal variable;

Example;

Output;

Also, are you aware of the dynamic variables available for this sort of thing?

Example;

Output;

Hope this helps.

1 Like

Thanks for your revert ,but as my input body takes as whole string with backward slashes (" ") as shown in below request body so how can i pass name as variable in request body .
{“parameterData”: “{“action”: “Insert”,“name”: “Lauren”}”}

if i will try passing variable as name in below request body then i am getting error in response : (

{“parameterData”: “{“action”: “Insert”,{{name}}”}

Please advise any way to pass this variable as input body request body is defined as whole string rather than plain vanilla json body :frowning:

Looks like you’re missing some quotes and a closing bracket…


image


Try;

{"parameterData": "{\"action\": \"Insert\",\"{{name}}\"}"}

same error :frowning:

Thanks James ,you are really helpful so far .i am still not able to post this request body successfully with “name” as variable .please assist me

I made a mistake when comparing to your original question, I missed a property.

Try;

{"parameterData": "{\"action\": \"Insert\",\"name\": \"{{name}}\"}"}

Are there any docs you are working from? 1

Thank you James ,you are awesome .my issue resolved now

1 Like