Payload details in pm.sendRequest()

I need to pass the entire request payload as variable in pm.sendRequest() method.For it,I have saved the request payload in environment and got it from env.

It is not working as varaibles values which are in payload not getting updated and sending as variable string

Hey @spacecraft-technol17 :wave:

Welcome to the Postman Community! :postman:

What is the value of the “AddJob” variable? Is it what you have in the second image?

How was that initial stored and are the variables ({{JobName}}, etc.) within the payload, also stored in the environment?

Have you tried using:

  body: {
    mode: 'raw',
    raw: pm.environment.replaceIn('{{AddJob}}')
  }

@danny-dainton Thanks for your reply…

At intial,I have set the entire payload structure at enviroment by creating a variable called “AddJob” and assign the below payload(Example) as intial value.Variable values will be stored from API call 1,2,3,4 response
{
“key1”: {{JobName}},
"key2: {{JobId}},
“key3”: {{CompanyId}}
“key4”: {{CompanyName}},

}

At call 5,I have tried to get the “AddJob” variable from env and pass inside postman payload…It was working fine

But when tried to do the same call 5 via pm.sendRequest,variable values are sent as string not value.

Have you tried using:

  body: {
    mode: 'raw',
    raw: pm.environment.replaceIn('{{AddJob}}')
  }

As an example, I stored the variable like this:

let body = {
    "id": 1,
    "name": "Danny",
    "location": "{{location}}"
}

pm.environment.set('body', JSON.stringify(body))

I have another variable in the environment that is resolving the {{location}} placeholder.


1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.