XML as request for Exposed Rest API

Hi Team,


I have came across a requirement where I have to use XML as request for my Exposed Rest API.

But when I change it to XML and send Content-Type as Application/XML I get below error.

{
    "Errors": [
        "The request entity's media type 'application/xml' is not supported for this resource."
    ],
    "StatusCode": 415
}


Can someone help me with this.


Thanks

Atul


Hi Atul,

Using XML for REST APIs is not supported by the Platform. As far as I know you cannot change the Content-Type either (it will be ignored).

Hi Kilian,


Is there a workaround to achieve this.


Thanks

Atul


Hi Atul,

Not that I know of. If you need to consume such an API, there are several options, but exposing a REST API that uses XML is just not possible.

(Note I consider it a Platform bug that it's not possible to override the Content-Type header, but that's the current state of affairs.)

EDIT: I recalled this topic, in which a possible solution was offered, but I was never able to verify whether this works.

Hi Kilian,


I have seen this post and I was able to achieve the same where for GET request I was able to return the response as XML with Content-Type as application/xml, but here I am using the POST request and not able to override the Request header.


Thanks

Atul

Hi Atul,

Are you talking about another service that POSTs to your exposed API? Or are you talking about POSTing to another service? I was assuming the first, and also assuming that it didn't matter much whether the client uses GET or POST to access your API?

Hi Kilian,


another service that POSTs to my exposed API.


"assuming that it didn't matter much whether the client uses GET or POST to access your API" It matters because if I am expecting some payload to be send then it has to come via POST.


Thanks

Atul

Atul,

Please review this thread and see if it helps you. 

https://www.outsystems.com/ideas/1751/consuming-rest-services-with-xml

Thanks,

Erik

Atul,

If you want to receive XML, you can just parse whatever XML you get (see also the Idea Erik mentions, it has some possible solutions). To return XML to the sender with the right Content-Type, see a possible solution in the topic I linked to earlier.