How do I convert XML to JSON AWS API Gateway?

Question:

I am trying to use Amazon’s AWS API gateway to front legacy SOAP services with REST. I am able to take a resource request and basically hard code SOAP request in a Body Mapping Template. The SOAP service is called and the XML SOAP response is returned. So far so good.

In the Integration Response, I need to take this SOAP envelope (Basically just XML) and map that back to the JSON model. I don’t see how this can be done, but I must be missing something. The following code will get the raw response, but I don’t see any way to access the elements:

Then in a Body Mapping Template, I want to do something like this:

Answer:

API Gateway does not currently support direct transformation of XML response bodies. This is a commonly requested feature and is on our backlog, so it will likely get implemented eventually. In the meantime, the only option is to us a Lambda function to call your SOAP back end, parse the response, and return JSON to API Gateway.

))
{
$input.body
}
Imagine my response looks like this:

Then in a Body Mapping Template, I want to do something like this:

I know I can probably write a Lambda function to call the SOAP service, but that just doesn't seem reasonable. Am I out of luck?

Answer:

API Gateway does not currently support direct transformation of XML response bodies. This is a commonly requested feature and is on our backlog, so it will likely get implemented eventually. In the meantime, the only option is to us a Lambda function to call your SOAP back end, parse the response, and return JSON to API Gateway.

))
{
"response-code" : "$input.Envelope.Body.getProdResponse.code",
"response-message" : "$input.Envelope.Body.getProdResponse.message"
}
I know I can probably write a Lambda function to call the SOAP service, but that just doesn’t seem reasonable. Am I out of luck?

Answer:

API Gateway does not currently support direct transformation of XML response bodies. This is a commonly requested feature and is on our backlog, so it will likely get implemented eventually. In the meantime, the only option is to us a Lambda function to call your SOAP back end, parse the response, and return JSON to API Gateway.

))
{
$input.body
}Imagine my response looks like this:

Then in a Body Mapping Template, I want to do something like this:

I know I can probably write a Lambda function to call the SOAP service, but that just doesn’t seem reasonable. Am I out of luck?

Answer:

API Gateway does not currently support direct transformation of XML response bodies. This is a commonly requested feature and is on our backlog, so it will likely get implemented eventually. In the meantime, the only option is to us a Lambda function to call your SOAP back end, parse the response, and return JSON to API Gateway.

Leave a Reply