Rest > Soap (using POST), json payload parameters are not propagated

Not applicable

Hi,

I need to use a Soap API and expose it as REST.

Something just like the Weather API discussed in the tutorial/doc

http://docs.apigee.com/tutorials/proxy-soap-service

However, in my case, instead of using GET, I have to use POST with the parameters in a json payload.

So instead of doing this

GET http://mikaelw-test.apigee.net/weatherrest/cityweatherbyzip?ZIP=07030

I need to do this:

POST http://mikaelw-test.apigee.net/weatherrest/cityweatherbyzip

{
    "ZIP":07030
}

with apigee taking the parameter from the posted json payload and making the normal SOAP call with it.

At the moment, it doesn't seem to work, the call reach the target but without the parameter. It returns:

{
    "GetCityWeatherByZIPResponse":{
        "GetCityWeatherByZIPResult":{
            "Success":"false",
            "ResponseText":"Invalid ZIP",
            "State":{
            },
            "City":{
            },
            "WeatherStationCity":{
            },
            "WeatherID":-1,
            "Description":{
            },
            "Temperature":{
            },
            "RelativeHumidity":{
            },
            "Wind":{
            },
            "Pressure":{
            },
            "Visibility":{
            },
            "WindChill":{
            },
            "Remarks":{
            }
        }
    }
}

What should i do to make sure parameters are taken from my json payload and propagated to the SOAP target call? Many Thanks

Solved Solved
0 1 1,387
1 ACCEPTED SOLUTION

Not applicable

Actually, this is all related to those ExtractVariable block.

See this: http://docs.apigee.com/api-services/reference/extract-variables-policy

So in this case, something like this should be used:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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>

in Api > Develop > policy (the one corresponding to the first step of your PUT)

View solution in original post

1 REPLY 1

Not applicable

Actually, this is all related to those ExtractVariable block.

See this: http://docs.apigee.com/api-services/reference/extract-variables-policy

So in this case, something like this should be used:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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>

in Api > Develop > policy (the one corresponding to the first step of your PUT)