I've encountered a problem regarding mapping values using liquid for a "Soap to Rest" api endpoint in API management policys.
My Example looks something like this...
The Soap Request should return something like this:
<Response>
<Truck>
<ID>098NJ2139UND324<ID>
<LicenceNumber>MKL025</LicenceNumber>
<Cargo>
<CargoLicenceNumber>BHJ897</CargoLicenceNumber>
<Cargo>Candy</Cargo>
</Cargo>
<Cargo>
<CargoLicenceNumber>TGA916</CargoLicenceNumber>
<Cargo>Fireworks</Cargo>
</Cargo>
</Truck>
</Response>
My Liquid Code sample in the "out" policy in API management looks something like this:
{
"Response": {
"id": "{{body.envelope.body.Response.ID}}",
"licencenumber": "{{body.envelope.body.Response.LicenceNumber}}",
"cargo": [
{% JSONArrayFor item in body.envelope.body.Response where Cargo -%}
{
"cargolicencenumber": "{{item.CargoLicenceNumber}}",
"cargo": "{{item.Cargo}}"
}
{% endJSONArrayFor -%}
]
}
}
But the converted XML to Json looks like this:
{
"Response":{
"ID": "098NJ2139UND324",
"LicenceNumber": "MKL025",
"Cargo": [{
"CargoLicenceNumber": "BHJ897",
"Cargo":""
},
{
"CargoLicenceNumber": "TGA916",
"Cargo":""
}
]
}
}
I'm missing this "Cargo" value in the array. I know The Setup is a bit clunky as i think the name of the array object "Cargo" should be "Trailer" or something like that (NOTE: This is an example, not the real object I'm working with). The Array having the same name as the array Sub-element is what i think is causing the problem.
As I'm not the owner of the SOAP WSDL i used to import to API management to in turn convert to a rest API, I cant easily change the name of the Array in the service. There for I'm wondering if there is a way to force liquid to find the value of the element in the array some how?
Also, worth mentioning is: as i was troubleshooting the code i changed the "{{item.Cargo}}" part to "{{item.CargoLicenceNumber}}" and that found the license plate number without any problems. So I'm thinking something in the back end is definitely getting confused by the name of the property.
Has anyone else encountered this problem before?
Thanks in advance.