XML to JSON template conversion not working

Here i am hitting soap api

api documentation link: TempConvert Web Service

as i don’t add any transformation or modification using tyk cloud methods. it works fine and give me result according to documentation shown (i am following SOAP1.1)

Now what i need is to change the SOAP api result to JSON , so for that i use template in response body tranformation like

Input
<?xml version="1.0" encoding="utf-8"?>
soap:Envelope
soap:Body

121.111111111111

</soap:Body>
</soap:Envelope>

Template
{
“FahrenheitToCelsiusResponse”: “{{.Envelope.Body.FahrenheitToCelsiusResponse.FahrenheitToCelsiusResult}}”

}

Output
{
“FahrenheitToCelsiusResponse”: “121.111111111111”

}

on sample Test it works fine

But as i use it in POSTMAN it shows the result :

result:
{
“FahrenheitToCelsiusResponse”: "
"

}

Please help me to know why this is happening and what step to be taken to correct it.
and also help to how i can send form data and do transformation.
Thanks in advance

What is the response code in Postman? Is the request successful. It could be blank because it is failing somehow.

1 Like

According to the docs at TempConvert Web Service you are sending a http POST all you need in the request body is Fahrenheit=string where string is the temperature value.

I’ll test this all and get back to you.

Ya i noted but tyk is not accessing this Fahrenheit=string and giving me response to , like it not getting that body part. and in tyk till i am not able to send query or post data to tyk, without tyk api working fine in postman but as i configure it in tyk api giving me blank response, please give atleast one video or blog of how to send data in tyk using post,get method

I checked and the upstream service doesnt seem to be up which is why you cant get a proper response. The steps you are taking are correct from what i can tell.

Can you pls try the following notation using “index” function, which basically allows you to specify path too, but works a bit different.

{
“FahrenheitToCelsiusResponse”: “{{index . "Envelope" "Body" "FahrenheitToCelsius" "Fahrenheit"}}”
}

Also It can be very handy to write values like “{{index . }}” to introspect XML object, same as Tyk sees it. Note that you should use curl instead of browser to examine such responses, because if there is non compilat JS or XML, browser will fail to show it, but curl will.

Hope it helps!

Thanks for response, but it giving me result { "result":"

I made it work for this SOAP API, and in the process found a bug: Tyk can’t properly transform body if server use compression and client passed Accept-Encoding header. Go HTTP usually automatically handle response compression, except the case when the client specifies Accept-Encoding header, and Postman in this case does. So when I disabled this header in postman by setting it empty, it started working. Here is how my postman call looks:

Regarding Tyk setup, it was quite simple, API base url XML Tutorial, and POST tempconvert.asmx path, and body transform mentioned above:

{
"FahrenheitToCelsiusResponse": "{{index . "Envelope" "Body" "FahrenheitToCelsiusResponse" "FahrenheitToCelsiusResult"}}"
}
1 Like

Thanks but i dont know on my side m getting this result as blank , i am using cloud tyk. help me out why this is happening, whenever i convert xml to json i get this type of result

my template is same as yours
{
“FahrenheitToCelsiusResponse”: “{{index . “Envelope” “Body” “FahrenheitToCelsiusResponse” “FahrenheitToCelsiusResult”}}”
}

Your SOAPAction header is in quotes, try it without them?

Done still getting same result, can you tell what can be the reason. as every time xml to json i face same problem

Thanks