Forum Stats

  • 3,825,182 Users
  • 2,260,478 Discussions
  • 7,896,431 Comments

Discussions

Multiple API response xml into one XML

3409470
3409470 Member Posts: 6
edited Apr 8, 2020 5:52AM in BPEL

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

Answers

  • 3409470
    3409470 Member Posts: 6
    edited Apr 6, 2020 3:38PM

    Hello,

    Any suggestions would be helpful?,,

    @Martien van den Akker

    thanks,

    ebsor

  • Martien van den Akker
    Martien van den Akker Member Posts: 2,776 Bronze Crown
    edited Apr 7, 2020 4:30AM

    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

    pastedImage_0.png

    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

  • 3409470
    3409470 Member Posts: 6
    edited Apr 7, 2020 7:53AM

    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

  • Martien van den Akker
    Martien van den Akker Member Posts: 2,776 Bronze Crown
    edited Apr 7, 2020 8:02AM

    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

  • 3409470
    3409470 Member Posts: 6
    edited Apr 7, 2020 8:16AM

    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

  • Martien van den Akker
    Martien van den Akker Member Posts: 2,776 Bronze Crown
    edited Apr 7, 2020 8:55AM

    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:

    pastedImage_0.png

    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

  • 3409470
    3409470 Member Posts: 6
    edited Apr 8, 2020 5:52AM

    Hi Martein,

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

    best regards,

    ebsor