Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse XML response to another requests in Postman

I must to test a few webservices who response in XML format and i want to parse the response from first request to second request call.

Ex: I make a first request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:exec>
         <!--Optional:-->
         <ser:sName>55</ser:sName>
         <!--Zero or more repetitions:-->
         <ser:sArguments>{{Param1}}</ser:sArguments>
         <ser:sArguments>XX</ser:sArguments>
         <ser:sArguments>POSTMAN</ser:sArguments>
         <ser:sArguments></ser:sArguments>
         </ser:exec>
   </soapenv:Body>
</soapenv:Envelope>

who response with:

<soap:Body>
        <ns2:execResponse xmlns:ns4="http://address.com" xmlns:ns3="http://services" xmlns:ns2="http://services.com">
            <ns2:execReturn>6666&#xd;
</ns2:execReturn>
        </ns2:execResponse>
    </soap:Body>
</soap:Envelope>

And i want to put 6666 in a GlobalVariable or EnvironmentVariable to use in second request call.

What i try untill now:

First i set a parameter(NumberReq) in Manage Environments - GLOBALS then in TESTS i put this code:

var jsonData = xml2Json(responseBody);
postman.setEnvironmentVariable("NumberReq", jsonData.execReturn);

And in the next request i try to use the NumberReq param like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.com">
       <soapenv:Header/>
       <soapenv:Body>
          <ser:exec>
             <!--Optional:-->
             <ser:sName>99</ser:sName>
             <!--Zero or more repetitions:-->
             <ser:sArguments>00</ser:sArguments>
             <ser:sArguments>{{NumberReq}}</ser:sArguments>
             <ser:sArguments>{{Param2}}</ser:sArguments>
             <ser:sArguments>{{Param3}}</ser:sArguments>
             </ser:exec>
       </soapenv:Body>
    </soapenv:Envelope>

I have a collection with this two webservices and i run from Postman Runner, but don't work to parse the response.

Can anyone help me? Thx! :)

like image 271
DET66 Avatar asked Mar 15 '17 14:03

DET66


1 Answers

I was able to come up with a slightly easier solution for reading from the xml response.

var xmlTree = xml2Json(responseBody);
var text = xmlTree["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ns1:loginResponse"]["loginReturn"]["_"];
var textstring = JSON.stringify(text);
console.log(textstring);
postman.setEnvironmentVariable("loginReturn", textstring);

Here is the response

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:loginResponse>
            <loginReturn xsi:type="xsd:string">b1c705515532a9abc353b32e91de3b97</loginReturn>
        </ns1:loginResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

HOWEVER, I am not able to utilize the variable I saved to Environment in subsequent request using the following format

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:shoppingCartCreate soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <sessionId xsi:type="xsd:string">{{loginReturn}}</sessionId>
         <storeId xsi:type="xsd:string">1</storeId>
      </urn:shoppingCartCreate>
   </soapenv:Body>
</soapenv:Envelope>
like image 102
user2332195 Avatar answered Oct 18 '22 03:10

user2332195