# How to append a request body (Saved to a environment variable from previous response)

**URL:** <https://community.postman.com/t/how-to-append-a-request-body-saved-to-a-environment-variable-from-previous-response/23750>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json\
**Created:** [May 14, 2021, 7:31pm UTC](https://community.postman.com/t/how-to-append-a-request-body-saved-to-a-environment-variable-from-previous-response/23750 "2021-05-14T19:31:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansarise](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@ansarise](https://community.postman.com/u/ansarise)\
**Post date:** [May 14, 2021, 7:31pm UTC](https://community.postman.com/t/how-to-append-a-request-body-saved-to-a-environment-variable-from-previous-response/23750/1 "2021-05-14T19:31:47Z")

</div>

Hi Folks,  
Hope you all are doing great…

I have a situation where i need to capture the response from previous request and save it to an environment variable and append it with some fixed json code and then use it as a request payload - body in the next request.

**Request 1 - I am capturing the response and saving it to an environment variable**

var jsonResponse = pm.response.json(); var getJsonResponse = JSON.stringify(jsonData);

pm.environment.set(“details”, getJsonResponse);

Below is the response captured and assigned to the above variable:

{

“programNumber”: “xxxxxxxxxxxxx”,

“wpType”: “xxx”,

“referralType”: “xxxxxxxxx”,

“status”: “xxx”,

“openDate”: “2017-04-27”,

“transitional”: false,

“benefitAmount”: 357.0,

“requirementsMet”: false,

“reopenInd”: false,

“userModel”: {

“offices”: ,

“roles”:

}

}

Now i want to append the below JSON part to the response saved to the environment variable and send it as a request body for next request

**,**

**"$promise": {},**

**"$resolved": true,**

**"staffId": “xxxxxx-18cf-xxxx-b18d-xxxxxxxxxx”,**

**"transitionalDate": null**

---

<div class="post-metadata">

**Author:** ![ansarise](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@ansarise](https://community.postman.com/u/ansarise)\
**Post date:** [May 15, 2021, 5:23am UTC](https://community.postman.com/t/how-to-append-a-request-body-saved-to-a-environment-variable-from-previous-response/23750/2 "2021-05-15T05:23:03Z")

</div>

I have the answer for my question posted here.

We can use Object.assign to merge two objects in JavaScript

const postmanResponse = { name: “xxxxx”, age: 22 };

const appendJsonCode = { dob: 05/05/1990, pin: 123456 };

const newResponse = Object.assign(response, additional);  
pm.environment.set(“nextRequestBody”, JSON.stringify(newResponse));

Thank you
