Extracting an Array from JSON and Build SOAP Request according to number of entities i receive in JSON Request

Not applicable

Hi Team, I have following requirment. My Apigee Proxy receiving JSON Data and will create a SOAP Request.

Samples are :-

SOAP :-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:main>
         <sessionId>?</sessionId>
         <productsData>
            <!--Zero or more repetitions:-->
            <complexObjectArray>
               <!--Optional:-->
               <product_id>?</product_id>
               <!--Optional:-->
               <qty>?</qty>
</complexObjectArray>
</productsData>
</urn:main>
JSON Incoming Sample :-
 {
       "main":
       {
          "sessionId":"696",
"productdata":[{"product_id":"pp1","qty":"5"},{"product_id":"pp2","qty":"8"}]
       }
    }

This product data can be multiple times of which we dont have control, Now we need to build soap request such that , whatever number of productdata we receive that much tags get build in soap request For this JSON input ...... 
SOAP Req should be :-
      <urn:main>
         <sessionId>696</sessionId>
         <productsData>
            <complexObjectArray>
               <product_id>pp1</product_id>
               <qty>5</qty>
</complexObjectArray>
<complexObjectArray>
               <product_id>pp2</product_id>
               <qty>8</qty>
</complexObjectArray>
</productsData>
</urn:main>
But problem is I am not able to configure policies for this kind of requirment , please provide a sample policy for same Or give me pointers where this requirment is documented in your support docs so that i can go through them.
Thanks in Advance
Solved Solved
1 3 1,512
1 ACCEPTED SOLUTION

Not applicable

This can definitely be done and there are multiple ways to do it.

One approach would be to set a flow variable equal to the productdata array using an Extract Variables policy. See the JSON tab for instructions to extract from a JSON payload. Then, you can use a JavaScript callout to assemble your SOAP message by adding the header information and then iterating through your flow variable and adding complexObjectArray elements as needed and then closing off the xml nicely. When done, set a flow variable equal to the final xml. Then, use an Assign Message policy to set the body of the request equal to the final xml flow variable.

View solution in original post

3 REPLIES 3

Not applicable

This can definitely be done and there are multiple ways to do it.

One approach would be to set a flow variable equal to the productdata array using an Extract Variables policy. See the JSON tab for instructions to extract from a JSON payload. Then, you can use a JavaScript callout to assemble your SOAP message by adding the header information and then iterating through your flow variable and adding complexObjectArray elements as needed and then closing off the xml nicely. When done, set a flow variable equal to the final xml. Then, use an Assign Message policy to set the body of the request equal to the final xml flow variable.

Good answer @Michael Malloy I think these are the situations we encounter on edge where it is necessary to use custom code and by providing custom code capability, edge developers have done a good job although it is best to use policies wherever possible.

I know the thread is very old.

Do we have any work around sample for the same.t will be very helpful