JSON to XML to create SOAP request envelope to be posted by POST

I am trying to dynamically create SOAP XML request body from JSON data to be processed by POST REST Web Service node. I was able to create XML request with all the input parameters but the only issue that I am facing is that the JSON to XML automatically adds XML tag on the top:

<?xml version="1.0" encoding="UTF-8"?>

But what I am looking for to add SOAP envelop wrapping the request

My current output is as below:

<?xml version="1.0" encoding="UTF-8"?>
<getGeoCodesRequest>
    <Addrs>
        <City>DENVER</City>
        <Country>UNITED STATES</Country>
        <PostCd>80212</PostCd>
        <State>COLORADO</State>
    </Addrs>
</getGeoCodesRequest>

My Expected output is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
   <soapenv:Body>
<getGeoCodesRequest>
   <addrs>
    <city>DENVER</city>
    <statePrv>COLORADO</statePrv>
    <postCd>80212</postCd>
    <cntry>UNITED STATES</cntry>
  </addrs>
</getGeoCodesRequest>
   </soapenv:Body>
</soapenv:Envelope>

I don’t see any configuration that will allow me to add this envelop tag within JSON to XML node.

Are there any other ways I can achieve this?

Please note that I am not able to achieve this using Generic Web Service client because I am unable to use local WSDL file for the SOAP request.

Hello @jaydeep1,

and welcome to KNIME Community!

You can try adding envelop tag to XML column using String Manipulation node (use join() function together with “\n” for new line). This will create String column and you can follow it with String To XML node.

Adding link to related topic of yours for others:

Br,
Ivan

2 Likes

Hi @jaydeep1 and welcome to the Community.

As @ipazin said, you can add the soap envelope manually with the join() function - you don’t really need to add the new line, it’s mostly for visual, or you could use some sort of “template” method and replace placeholders with values, and then submit the JSON via regular POST request.

If you will always have city, statePrv, postCd, cntry, I would simply create a template with placeholders like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
   <soapenv:Body>
<getGeoCodesRequest>
   <addrs>
    <city>##CITY##</city>
    <statePrv>##STATEPRV##</statePrv>
    <postCd>##POSTCD##</postCd>
    <cntry>##CNTRY##</cntry>
  </addrs>
</getGeoCodesRequest>
   </soapenv:Body>
</soapenv:Envelope>

And replace the placeholders (##CITY##, ##STATEPRV##, etc) with the appropriate values.

I put something together as an Example:
image

The template table contains the template I shared above. I convert it to a variable, as I intend to use the same template for multiple rows, which looks like this:

And my sample data is this:
image

I replace the placeholders like this:

And the final data is in the json_string column:

After that, you can send your data via the POST request:

Add your URL. You can also configure the concurrency (useful if you have a lot of rows to process, it will send multiple requests simultaneously), and you can also configure the timeout (the default 2 secs should be enough, but if you are going to do concurrency and a lot of records, you want to give it a better chance to continue by increasing the timeout limit, rather than failing in the middle, which will then be a pain to resume)

Some endpoint might require that you pass some headers with your request, this is where you would add them:

And this is where you pass the body:

Here’s the workflow:
SOAP template.knwf (12.6 KB)

1 Like

Thanks so much for the proposed solution… I will try to implement this in my workflow… Appreciate it!!