JSON to XML

Hi,

I'm new to Celigo and I wanted help with something.

I have a source app that returns a list of records in a JSON format. I want to turn that JSON into an XML and post it to an import app. Right now I'm using a transformation and JS like this:

function transform(options) {

let final_xml="";

const record=options.record;

//Create XML

final_xml+=`

<outbound_shipment>

<shipment_master>

<WarehouseID>${record["warehouse_code"]}</WarehouseID>

<OrderNumber>${record["shipment_id"]}</OrderNumber>

</shipment_master>

</outbound_shipment>`;

return final_xml;

}

the import gets the correct XML, but says The record should be of data-type object.

Thanks in advance for any help!

1

Comments

1 comment
Date Votes
  • Sergio Garcia fundamentally, everything within a Celigo flow has to be JSON. When an api returns CSV, EDI, XML, etc, we convert it to JSON and that JSON goes through the flow. If you then need to send XML to a destination, you would set the connection to XML or override the media type to XML and then build the XML structure in the request body. You could also go the script route, but the output of the script has a single JSON field with all the XML you've made and then you use a handlebar expression in the request body that is the XML field of your JSON record. Here is an example:

    -1

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post