Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Creating SOAP request from JSON array

I have JSON request with array that needs to be sent as SOAP request in back end. Can anyone please help that how can I construct repeated occurrence in SOAP message

JSON:

{
  "requestList": [{
    "accountLevel": "CL",
    "accountPortfolio": "01",
    "account": "608859577"
  }, {
    "accountLevel": "CL",
    "accountPortfolio": "01",
    "account": "607364694"
  }]
}


SOAP

<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="urn:2DD4107F-4052-491E-8D41-FBDE9171A2EF">
  
  <soap:Body>
    <ns1:RequestName>
      <ns1:item> 
        <ns1:accountLevel>CL</ns1:accountLevel>
        <ns1:accountPortfolio>01</ns1:accountPortfolio>
        <ns1:account>608859577</ns1:account> 
      </ns1:item> 
      <ns1:item>
        <ns1:accountLevel>CL</ns1:accountLevel>
        <ns1:accountPortfolio>01</ns1:accountPortfolio>
        <ns1:account>607364694</ns1:account> 
      </ns1:item>
    </ns1:RequestName>
  </soap:Body>

</soap:Envelope>


I could do for 1 occurrence by parsing the JSON request in JavaScript policy and stored the request elements in variables. I used Assign Message policy to construct SOAP payload by inserting those variables.

But this logic will not work if there are multiple dynamic occurrences in request as I cannot write conditional logic in Assign Message policy.

How can I accomplish this?

Solved Solved
0 5 1,825
1 ACCEPTED SOLUTION

Here's an example that

  • uses JSONToXML to transform the original JSON into XML
  • Uses XSL to transform the XML into XML with the right form and namespaces, embedded into a SOAP envelope.

For an input of

{
  "requestList": [{
    "accountLevel": "CL",
    "accountPortfolio": "01",
    "account": "608859577"
  }, {
    "accountLevel": "CL",
    "accountPortfolio": "01",
    "account": "607364694"
  }]
}

The output is:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:ns1="urn:2DD4107F-4052-491E-8D41-FBDE9171A2EF"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns1:RequestElement>
         <ns1:item>
            <ns1:accountLevel>CL</ns1:accountLevel>
            <ns1:accountPortfolio>01</ns1:accountPortfolio>
            <ns1:account>608859577</ns1:account>
         </ns1:item>
         <ns1:item>
            <ns1:accountLevel>CL</ns1:accountLevel>
            <ns1:accountPortfolio>01</ns1:accountPortfolio>
            <ns1:account>607364694</ns1:account>
         </ns1:item>
      </ns1:RequestElement>
   </soap:Body>
</soap:Envelope>


...which I think is what you wanted.

apiproxy-pradeep-soap.zip

View solution in original post

5 REPLIES 5