JSON to XML for error case

I have created an API by specifying HTTP service as a target. The source system will accept the only XML. Since I have added OAuth 2.0 feature in case of Authorization fail the response from Tyk gateway is in JSON format. How to resolve this issue.

Mohamed Shalik

Hi Mohammed

Could you provide a bit more information about tglhe request flow and what you need to happen ideally?

Hello Josh,

Here I have attached the request with invalid Key and the response. I need this response in XML format.


Content-Type: text/xml
Authorization: Bearer nb3557bfb528d49707bf1d8878a5e19a491447d8679267c193d0621

<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/”>
<soap:Header xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”>
<oas:Security xmlns:oas=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” >

			<!--You may enter ANY elements at this point-->
	<GetTrackandTraceRequest >



content-type: application/json

“error”: “Key not authorised”

So you want the error response to be in XML? That is not possible without some kind of custom middleware which would hijack the request pre-auth and send back an XML response.

Sorry if i’m not understanding you well

Yes I need response to be XML pre-auth. Do you have any document or blog for the same. Can you elaborate the custom middleware and hijack request part


Ultimately Tyk is a REST Gateway so is not designed to return XML from it’s internals. However you could use something like javascript preauth middleware to check if Authorization header is present and return xml response if not https://www.tyk.io/docs/customise-tyk/plugins/javascript-middleware/middleware-scripting-guide/