Https endpoint to return XML

Within the UI, the https endpoint feature only supports returning json/ejson. Is there a way to return XML?
I intend to build an integration with plivo and for call controlling plivo expects an XML document.
Thanks

Anybody have any answer to this? I also need to return XML?

If HTTPS Endpoints/Functions cannot return XML — then what are the alternatives?

Hi @Adedayo_Ayeni & @Tim_N_A,

This is only partially true: yes, the docs gear towards the JSON/EJSON format as result, and indeed if you set the Respond With Result toggle, the conversion to the chosen format is automatic.

But, this isn’t the only possibility: if you don’t set the flag, you can manipulate the response directly, and the body can be any string, thus including an XML representation, providing that you set the proper Content-Type, of course.

For example, the following Function, connected to an endpoint, is perfectly possible:

exports = function({ query, headers, body}, response) {
    response.setHeader("Content-Type", "text/xml");
    response.setBody('<?xml version="1.0"?><data></data>');
    response.setStatusCode(200);
};

And this runs

curl 'https://data.mongodb-api.com/app/<app-id>/endpoint/testXML' \
 -H 'Accept: "*/*"' \
 -H 'api-key: <API Key>'
<?xml version="1.0"?><data></data>

Obviously, your Function will likely need to add external dependencies to manipulate the XML, but, as long as the libraries you choose are compatible with the environment they’ll run in, it should work.

1 Like

Thanks @Paolo_Manna !! I think I got that working.