So, I’m working with a third party soap service and we are trying to expose it as Rest using Apigee.
It is working for simple calls exposed as Rest GET.
When many parameters needs to be passed, we use a Rest POST json payload.
For example, if we use the famous weather soap service as an example, we would want to turn this json from our Rest POST call…:
{
"ZIP":"07030"
}
…into that soap XML sent to the third party service.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><GetCityWeatherByZIP xmlns="http://ws.cdyne.com/WeatherWS/"><ZIP>07030</ZIP></GetCityWeatherByZIP></soap:Body></soap:Envelope>
It works perfectly fine, we use this kind of policy with some jsonpath:
<ExtractVariables async="false" continueOnError="true" enabled="true" name="GetCityWeatherByZIP-extract-form-param">
<DisplayName>GetCityWeatherByZIP Extract Form Param</DisplayName>
<Source clearPayload="true|false">request</Source>
<JSONPayload>
<Variable name="ZIP" type="string">
<JSONPath>$.ZIP</JSONPath>
</Variable>
</JSONPayload>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</ExtractVariables>
=====
However, in some cases, the calls and their payloads are more complicated, involving nested structures and arrays (because the third party service is like that). We are not too sure what is the best way to extract a list of a values from a json array and populate the corresponding section of a soap xml envelope, for example, if we want to turn this:
{
"apiSessionId":"123456",
"calendarId":"111",
"userId":"222",
"slots":[
1,
2,
3
]
}
into this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://www.q.com/Services" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header/>
<soapenv:Body>
<ser:LockSlots>
<ser:apiSessionId>123456</ser:apiSessionId>
<ser:calendarId>111</ser:calendarId>
<ser:userId>222</ser:userId>
<ser:slots>
<arr:short>1</arr:short>
<arr:short>2</arr:short>
<arr:short>3</arr:short>
</ser:slots>
</ser:LockSlots>
</soapenv:Body>
</soapenv:Envelope>
How would you do it? Is it possible with just jsonpath and policies? Do we need to use something else like javascript? Many Thanks