7 Replies Latest reply on Apr 8, 2020 9:52 AM by 3409470

    Multiple API response xml into one XML

    3409470

      Hi,

      I have am calling 2 APIS which return JSON and I convert them to xml

       

      Orders                - takes customer_id return xml with all the orders

      Order payments - it takes order_id and return xml for one order

       

      Now my problem is how to loop through all the orders and call payments API in BPEL and save the response xml in one xml into database.

       

      I am new dont have much idea how to do it?

       

      thanks

      ebsor

        • 1. Re: Multiple API response xml into one XML
          3409470

          Hello,

           

          Any suggestions would be helpful?,,

          Martien van den Akker

           

           

          thanks,

           

          ebsor

          • 2. Re: Multiple API response xml into one XML
            Martien van den Akker

            Hi,

             

            How is your process triggered?

             

            With 12.2.1 you would be able to use javascript within BPEL. But I haven't done that yet. Actually, in all of the projects I'm on, we just use SOAP/XML.

            In fact BPEL uses XML, so JSON will be transformed to XML.

             

            In your case I would use the REST adapter to

             

            Then use a BPEL for loop on every occurence in the customer list.

            For every customer-id use another REST adapter to fetch the orders for that customer and process those in another for loop.

             

            Make sure you create a BPEL 2.0 process. Then you can use the for-each loop. That is quite convenient.

             

            Hope this helps?

             

            Kind regards,
            Martien

            • 3. Re: Multiple API response xml into one XML
              3409470

              Hi,

              thanks Martien, how I store those xml response into one XML in the database, that I am not sure.

               

              Today for every API we get one response ans we store it.

               

              regards

               

              ebsor

              • 4. Re: Multiple API response xml into one XML
                Martien van den Akker

                Hi Ebsor,

                 

                Do you have a data model present in the database? Or do you need to store them as xml files?

                In either way, you'll need to use the database adapter to do so. If you have a datamodel, then the database adapter will create an xsd for every insert you'll define. Depending on the datamodel you might need to do an insert for the customer and an other insert for the orders. Thus 2 adapters. Perhaps you could do  it in one Database adapter insert, when you can define a parent-child relation between the customer and the orders.

                 

                If you need to insert it as an xml into the database in a CLOB column for instance, then you'll need the XSD that defines the XML. You can then use an XSLMap to transform to the correct XML format. And then do an insert.

                 

                 

                Kind regards,
                Martien

                • 5. Re: Multiple API response xml into one XML
                  3409470

                  Hi,

                   

                  May be I did not put my question correctly,

                   

                  for 1 customer  I get 5orders

                                                               for those 5orders we will make 5 payment API calls which result 5 xml response.

                  I need these 5 response xml merge into one XML and save into database as single xml in xmltype column.

                   

                  regards,

                  ebsor

                  • 6. Re: Multiple API response xml into one XML
                    Martien van den Akker

                    Ah, You'll need to create a variable based on the XSD of the single xml type.

                    Let's say it has a structure like

                    <payments>

                      <payment>

                        <order-id>

                        <quantity>

                        <amount>

                       </payment>

                    </payments>

                    The first payment you'll just use a regular assign copy-rule to /payments/payment. For every subsequent payment, you'll need another assign with a copy rule with /payments as a target, but change the rule to append:

                    So you'll need an if around it to check on the index. Or maybe you could do also an append for the first one. You  should try that.

                     

                    Kind regards,
                    Martien

                    • 7. Re: Multiple API response xml into one XML
                      3409470

                      Hi Martein,

                       

                      Thanks for this information, I will try to implement this solution and then will comeback.

                       

                      best regards,

                      ebsor