cancel
Showing results for 
Search instead for 
Did you mean: 

Sending raw XML payload

woutf
Deputy Chef I
Deputy Chef I

I’m trying to send a raw request using the connector SDK. I have a string containing a cXML payload that Workato needs to forward as-is to an API endpoint. Here is an example snippet of the payload:

<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.035/InvoiceDetail.dtd">
<cXML payloadID="1234" timestamp="2026-01-20T00:00:00+01:00" version="1.2.024" xml:lang="NL">
    <Header>
        ...
    </Header>
    <Request Id="cXMLData" deploymentMode="production">
        ...
    </Request>
</cXML>

However, the .format_xml method requires a root XML element, which already exists in the input string. Additionally, the input includes the XML declaration and DOCTYPE, neither of which are supported by .format_xml. The method also requires the payload to be converted to JSON first.

As a result, I’m forced to transform the XML to JSON and then back to XML, which isn't ideal:

# Remove XML declaration and DOCTYPE using regex
        xml_body = xml_body.gsub(/\A<\?xml.*?\?>\s*/m, '')          # remove <?xml ... ?>
        xml_body = xml_body.gsub(/<!DOCTYPE.*?>\s*/m, '')            # remove <!DOCTYPE ... ?>

        # Parse XML into a hash
        parsed_xml = xml_body.from_xml
        parsed_xml = call(:replace_ampersands, call(:rename_lang_keys, parsed_xml)) # rename @lang to @xml:lang

        parsed_xml = {
          '@payloadID': parsed_xml['cXML'][0]['@payloadID'],
          '@timestamp': parsed_xml['cXML'][0]['@timestamp'],
          '@version': parsed_xml['cXML'][0]['@version'],
          '@xml:lang': parsed_xml['cXML'][0]['@xml:lang'],
          Header: parsed_xml['cXML'][0]['Header'],
          Request: parsed_xml['cXML'][0]['Request']
        }

        response = post('receiveInbCXML', parsed_xml)
        .request_format_xml('cXML')
        .response_format_xml()

I’ve also tried using request_format_raw, but it wraps the payload in string quotation marks, which the API endpoint does not accept.

Is there a simpler way to send a raw message to the API endpoint without modifying the payload?

1 REPLY 1

francbaviello
Deputy Chef II
Deputy Chef II

yes, there is a simpler and correct way, but it requires bypassing Workato’s XML/JSON formatters entirely and sending the payload as a raw HTTP body, not as a structured request. request_format_xml and request_format_raw are mutually exclusive with “send this string as-is”. If Workato is serializing anything for you, it will always modify the payload.

Do not use any request formatter and set the request body directly as a string:

xml_body = <<XML<?xml version="1.0"?><!DOCTYPE cXML SYSTEM http://xml.cxml.org/schemas/cXML/1.2.035/InvoiceDetail.dtd">.......

post('receiveInbCXML').headers('Content-Type': 'application/xml').body(xml_body)

This is the only way to forward cXML “as-is” in Workato.