# Inherit data from previous request - from request body

**URL:** <https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797>\
**Category:** Help Hub\
**Created:** [November 5, 2019, 1:05pm UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797 "2019-11-05T13:05:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theToncheff](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@theToncheff](https://community.postman.com/u/theToncheff)\
**Post date:** [November 5, 2019, 1:05pm UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797/1 "2019-11-05T13:05:42Z")

</div>

Hello, I’m trying to get data from my post request, specifically either from request or response body.  
Below is what I’m using to get data from the responseHeader.

```
pm.test("Create Account", function() {
    let headerValue = pm.response.headers.get("Neededdata");
    pm.globals.set("Neededdata", headerValue);
});

```

However, I cannot get it to work when I’m trying to extract data from response/request body, how can I call on the body?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 6, 2019, 10:11am UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797/2 "2019-11-06T10:11:44Z")

</div>

Hey @theToncheff

To get the `Request Body` data you can use the `pm.request` object and extract the details from there.

For example, this would set the raw `Request Body` as a `Global` variable:

```
pm.globals.set("requestBody", pm.request.body.raw)

```

Likewise, for the `Response Body` you can use the `pm.response` object to extract the data.

For example, this would set the raw `Response Body` as a `Global` variable:

```
pm.globals.set("responseBody", pm.response.json())

```

More information about the `pm.*` API functions can be found here:

[https://learning.getpostman.com/docs/postman/scripts/postman-sandbox-api-reference](https://learning.getpostman.com/docs/postman/scripts/postman-sandbox-api-reference)

Getting specific values from either of those would depend on the structure of the data, I don’t know what that is so this isn’t a _complete_ solution - Just a helping hand 🙂

---

<div class="post-metadata">

**Author:** ![murdoc-she-wrote](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/murdoc-she-wrote/32/2289_2.png) [@murdoc-she-wrote](https://community.postman.com/u/murdoc-she-wrote)\
**Post date:** [November 7, 2019, 6:21pm UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797/3 "2019-11-07T18:21:08Z")

</div>

If your response is in JSON format I recommend:

var jsonData = JSON.parse(responseBody);  
pm.environment.set(“variable name”, jsonData.path.to.value);

---

<div class="post-metadata">

**Author:** ![altimetry-operator-1](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@altimetry-operator-1](https://community.postman.com/u/altimetry-operator-1)\
**Post date:** [October 17, 2024, 4:46pm UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797/4 "2024-10-17T16:46:12Z")

</div>

This is not working now, The old one ( JSON.parse(responseBody); ) deprecated. Could you provide variable for below syntax

pm.response.text()

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 18, 2024, 7:37am UTC](https://community.postman.com/t/inherit-data-from-previous-request-from-request-body/8797/5 "2024-10-18T07:37:54Z")

</div>

Hey @altimetry-operator-1

As you’re responding to a comment that’s 5 years old - there might be some context that you need to provide here.

Can you fully expand on the details of your issue and the response you have, in order for people to assist you.
