# Get data from soap response into a variable

**URL:** <https://community.postman.com/t/get-data-from-soap-response-into-a-variable/5872>\
**Category:** Help Hub\
**Created:** [June 12, 2019, 10:15am UTC](https://community.postman.com/t/get-data-from-soap-response-into-a-variable/5872 "2019-06-12T10:15:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![koky](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@koky](https://community.postman.com/u/koky)\
**Post date:** [June 12, 2019, 10:15am UTC](https://community.postman.com/t/get-data-from-soap-response-into-a-variable/5872/1 "2019-06-12T10:15:56Z")

</div>

Hi all,I am new to post man and i want to get value from soap response body and put it inside a variable ,my test script is : var jsonObject=xml2Json(responseBody);  
var first\_name=jsonObject[‘SOAP-ENV:Envelope’][‘SOAP-ENV:Body’].serviceInquiryResponse.FIRST\_NAME;  
console.log(first\_name)

–I am getting the below error—  
TypeError| cannot read property ‘FIRST\_NAME’ of undefined

## the soap response appear as below (I want to get the value inside the first\_name tag and print it )

ns2:serviceInquiryResponse:{ }  
$:{ }  
ns2:rows: { }  
ns2:row: { }  
ns2:parameters: { }  
ns2:parameter:  
0 :{}  
1 :{}  
2 :{}  
3 :{}  
ns2:Key: “FIRST\_NAME”  
ns2:value: “test”

---

<div class="post-metadata">

**Author:** ![tmccann](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tmccann/32/3550_2.png) [@tmccann](https://community.postman.com/u/tmccann)\
**Post date:** [June 12, 2019, 1:58pm UTC](https://community.postman.com/t/get-data-from-soap-response-into-a-variable/5872/2 "2019-06-12T13:58:40Z")

</div>

@koky I have not done a ton of work with SOAP calls/responses in Postman but I did have to extract a value from a response once, this is an example of what I did if its any help.

````auto
var xml = cheerio.load(responseBody, {
  ignoreWhitespace: true,
  xmlMode: true
});

var elementContent = xml("LoginResult").attr("SessionHeader");
pm.environment.set("SessionHeader", elementContent);```
````

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [June 15, 2019, 6:49am UTC](https://community.postman.com/t/get-data-from-soap-response-into-a-variable/5872/3 "2019-06-15T06:49:30Z")

</div>

I think you are on the right track with xml2Json, you just need to find the right path to what you are looking more. Make sure you understand how arrays and objects work in JavaScript.
