# How to extract a specific value from a Request Body in POSTMAN and save in a variable

**URL:** <https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468>\
**Category:** Help Hub\
**Created:** [June 3, 2021, 2:25pm UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468 "2021-06-03T14:25:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 3, 2021, 2:25pm UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/1 "2021-06-03T14:25:00Z")

</div>

Is there any way to get a specific value ( `type="Bank_Application_LOAN_JP_Answer"` ) from the Request body and save in a variable in postman?

Request Body

```auto
query_xml: "<ROWDATA type="Bank_Application_LOAN_JP">
<ReqID><![CDATA[A-13546]]></ReqID>
<AppNumber><![CDATA[RL048-00/21]]></AppNumber>
<DateTime><![CDATA[01/03/2010 14:57:42]]></DateTime>
<SID><![CDATA[0lebl74v2tr5nnuojvihjma0s0]]></SID>
<ReportType><![CDATA[01]]></ReportType>
<Participient ID="1110">
<KindBorrower>2</KindBorrower>
<TaxID>00000019</TaxID>
<FirmName>[CDATA[ՓԲԸ]]</FirmName>
<RequestTarget>1</RequestTarget>
<UsageRange>1</UsageRange>
</Participient>
</ROWDATA>"

```

I’ve been using this

```auto
let rowdataType = xml2Json(pm.request.body.raw);
pm.environment.set('rowdataType', rowdataType.type);

```

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 4, 2021, 1:01am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/2 "2021-06-04T01:01:01Z")

</div>

@harutharut,

Similar post is discussed in [this thread](https://community.postman.com/t/issue-with-xml-validation/24447). In the query of the post the user mentioned a way to your question.

You can use $, something like

```auto
console.log(jsonObject['ROWDATA'].$['type']);

```

It’s a guess based on the response you have provided. Please tweak it based on your request, also try exploring cheerio. Let us know if there’s still an issue to get the value 🙂

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 4, 2021, 6:08am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/3 "2021-06-04T06:08:16Z")

</div>

Hi @bpricilla , thank you for your answer.  
I have tried but the problem is actual. I can not to get the mentioned value from request body.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 4, 2021, 8:59am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/4 "2021-06-04T08:59:46Z")

</div>

Hello @harutharut,

Okay I get that, it should also work the same way as response. You cannot directly access the object using .type as in JSON.

How do you parse the response here? It’s the same. Just assign it to a different variable than responseBody.

Please try this:

```auto
console.log(pm.request.body.raw);
const request = xml2Json(pm.request.body.raw);
var rowdataType = request['ROWDATA'].$['type']
pm.environment.set('rowdataType', rowdataType);

```

I am throwing this path based on the request body you have mentioned. Please tweak based on your path 🙂

Else I would need the complete request 😊

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 4, 2021, 10:33am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/5 "2021-06-04T10:33:05Z")

</div>

maybe I should write pre-request script for getting that value? 🙂

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 4, 2021, 10:54am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/6 "2021-06-04T10:54:55Z")

</div>

let me show you the result.

 ![Screenshot_8](https://us1.discourse-cdn.com/getpostman/original/3X/2/c/2c5cc5fa185325dee1e5ec8e2838bace077c945b.png)  
 ![Screenshot_9](https://us1.discourse-cdn.com/getpostman/original/3X/5/a/5aabd6d0f91142e9a6d9e4fb267ddb449d73a097.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 4, 2021, 11:10am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/7 "2021-06-04T11:10:05Z")

</div>

@harutharut Are you using that variable “rowdataType” in the same request body as input/parameter?

If so, then you are right, it should go in pre-request script section 😊

```auto
console.log(pm.request.body.raw);
const requestBody = xml2Json(pm.request.body.raw);
var rowdataType = requestBody['ROWDATA'].$['type']
pm.environment.set('rowdataType', rowdataType);

```

I have update similar example in one of [public workspace collection](https://www.postman.com/bpricilla/workspace/pricilla-s-api-space/request/12539800-8c1d9bc3-b9dd-490b-8a51-1f11ed5e1f3f).

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 7, 2021, 7:31am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/8 "2021-06-07T07:31:35Z")

</div>

Hi @bpricilla , how are you?)

Is strange, but again no result.  
I sent request and set pre-request script, but again get error

```auto
undefined
TypeError: Cannot read property 'ROWDATA' of undefined

```

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 7, 2021, 10:58am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/9 "2021-06-07T10:58:01Z")

</div>

@harutharut , I am good thank you 😊 Hope you are safe too!!

I am sorry, I can’t assume things here, shall we connect please?

Drop me a message in [LinkedIn](https://www.linkedin.com/in/pricilla-b/).

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 7, 2021, 11:06am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/10 "2021-06-07T11:06:07Z")

</div>

ok, I have sent you connection request in Linkedin.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 8, 2021, 8:44am UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/11 "2021-06-08T08:44:07Z")

</div>

Based on our discussion your request type is not raw, it is “x-www-form-urlencoded”.

so try this snippet,

```auto
console.log(pm.request.body.urlencoded);

```

Similar to this [topic](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/8).

You can refer [this link](https://www.postmanlabs.com/postman-collection/RequestBody.html) for more details.

@harutharut It’s all the same details we discussed yesterday, sharing it here so that it might be useful for someone in future 😊

Please let me know if there’s still any issue.

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 10, 2021, 12:17pm UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/12 "2021-06-10T12:17:58Z")

</div>

Hi @bpricilla , thank you for your reply.  
Yes, my request type is “x-www-form-urlencoded”.  
At this moment, I have done a filter on all the parameters to show only ones that don’t have “disabled: true”  
So I have an object and want to have access to the type. Could you help me to find shortest way? 🙂

 ![Screenshot_10](https://us1.discourse-cdn.com/getpostman/original/3X/e/6/e6458ecc648f957a55111630d2439bb33aaa0eca.png)

---

<div class="post-metadata">

**Author:** ![harutharut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/harutharut/32/6996_2.png) [@harutharut](https://community.postman.com/u/harutharut)\
**Post date:** [June 14, 2021, 1:13pm UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/13 "2021-06-14T13:13:08Z")

</div>

Hi,  
I found the solution and want to share here, maybe it can be useful for someone)  
In my case I had several “x-www-form-urlencoded” key-values(rows). This snippet

`const requestBody = xml2Json(pm.request.body.urlencoded);`

can’t parse request body, and I had to filter before parsing. Let me show that part below

```auto
var params = pm.request.body.urlencoded.filter(function (param) {
    return param.disabled !== true;
});

const requestBody = xml2Json(params[0].value);
//console.log(requestBody['ROWDATA'].$['type']);
var rowdataType = requestBody['ROWDATA'].$['type']
pm.environment.set('rowdataType', rowdataType);

```

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [June 14, 2021, 11:57pm UTC](https://community.postman.com/t/how-to-extract-a-specific-value-from-a-request-body-in-postman-and-save-in-a-variable/24468/14 "2021-06-14T23:57:29Z")

</div>

Thanks for sharing the working snippet @harutharut 👏
