Using POST request in Postmat I received a body response as XML data like this.
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getAuthenticationTokenResponse xmlns:ns2="http://some_url.com" xmlns:ns3="http://some_url.com">
<return>111222333</return>
</ns2:getAuthenticationTokenResponse>
</S:Body>
</S:Envelope>
And I need to get somehow value 111222333 as a collection variable. And I’m lost with solution since I have no experience with JS before. Please provide me with some solution.
4
Answers
I'm really appreciate for all who give me help with this topic. Final version of solution is looks like this:
maybe
xml2js
can resolve your question.this is sample code:
xml2js is available in the Postman sandbox and gives you a lot more control over the output.
You are basically converting the XML to a JavaScript Object.
For example…
It depends on how complex your XML is, but have a look here (scroll to the bottom) for all of the formatting options.
https://www.npmjs.com/package/xml2js
Just enter "111222333" into your collection variable