Connecting to an external REST with an XML header

SOLVED

I am trying to connect to an external REST library that requires the content type to be XML and not JSON. The web service configuration seems to indicate that this should be possible since you can select XML as the the content type during the setup process. I know the URL, header, and body are correct as i can get the correct responses via Postman. 

However, when I attempt to execute the EXEC_REST_WS function, I get an error before it can complete the call it doesn't like the XML in the body of the call:

If i remove the XML from the body and replace it with a set of empty json brackets, then i get no x3 related errors but I get a response back from external services that obviously the call is crafted incorrectly because it can't support JSON.

Can anyone clarify if native ASYRRESTCLI can support REST applications using XML in the content type (and if not, why is it a selectable option in the configuration)? 

Follow up, if anyone else has bumped up against this, what did you do, if anything, to get around it?  This is a big issue for an active development project that I had not anticipated.

  • +1
    verified answer

    The ASYRRESTCLI function only accepts JSON as input and will only output data in JSON.

    The XML setting on the REST definition indicates the data exchange format to be used by the Syracuse HTTP Bundle ("@sage\syracuse-lib\src\http\client\httpApi.jsc"). 

  • 0 in reply to Regard Hulsbos

    Thank you. Any thoughts on a work around? This particular external API is exclusively XML payloads. 

    I found some documentation around building a 4GL accessible extension in javascript and deploying it in the node.js webserver.  If this worked i could use a standard XMLHttpRequest() in javascript to call the the API and then call the JS function in 4G. Should work in theory.  Documentation is a bit dated though (v7).

  • 0 in reply to bturner

    What is the return value in RESHEAD if you pass in the payload as JSON (not just the values of "{}", but rather the XML in JSON format)? The purpose of the XML setting on the REST definition is such that Syracuse will convert the JSON to XML on the REST call. I would recommend changing the following logging elements in the Global settings to "Silly":

    • REST
    • HTTP out
    • HTTP in

    This will give you the exact context calls made to the external REST service by Syracuse and you can determine if this standard REST service will be able to work for you or not. 

  • 0 in reply to Regard Hulsbos

    thank you, that helps to clarify. by chance, do you know how to structure the ASYRRESTCLI json payload in such a way that Syracuse would output the XML with the xmlns namespace and this tag attribute as follows: 

    <tns2:RatingRequest xmlns:tns2='schemas.3gtms.com/.../rating'>
          ...
          <GrossWeight UOM='Lb'>2650</GrossWeight>
          ...
    </tns2:RatingRequest>

    if i can figure this out i think it will work.