Assignmessage policy is not appending the query string parameters to the service callout url

Not applicable

My scenario is calling a service B with some parameters that are passed in the request query string. I have to introduce a service callout in the preflow to call service A with those parameters set in AssignMessagePolicy, get the response of A and extract the required fields using ExtractVariables policy and pass them to service B. I have done with what all required but the flow fails as service callout to service A is not having query string parameters in the url though they were set in ASsignMessagePolicy.

AssignMessagePolicy to service A:

<AssignMessage async="false" continueOnError="false" enabled="true" name="API-V1-Request"> <DisplayName>API V1 Request</DisplayName> <AssignTo createNew="true" type="request">InitializeAPIRequest</AssignTo> <Set> <QueryParams> <QueryParam name="apiKey">{request.queryparam.apiKey}</QueryParam> <QueryParam name="applicationId">{request.queryparam.applicationId}</QueryParam> <QueryParam name="twoDigitISOLanguageCode">{request.queryparam.twoDigitISOLanguageCode}</QueryParam> <QueryParam name="twoDigitISOCountryCode">{request.queryparam.twoDigitISOCountryCode}</QueryParam> </QueryParams> <Verb>GET</Verb> </Set> <!-- Set variables for use in the final response --> <AssignVariable> <Name>apiKey</Name> <Ref>request.queryparam.apiKey</Ref> </AssignVariable> <AssignVariable> <Name>applicationId</Name> <Ref>request.queryparam.applicationId</Ref> </AssignVariable> <AssignVariable> <Name>twoDigitISOLanguageCode</Name> <Ref>request.queryparam.twoDigitISOLanguageCode</Ref> </AssignVariable> <AssignVariable> <Name>twoDigitISOCountryCode</Name> <Ref>request.queryparam.twoDigitISOCountryCode</Ref> </AssignVariable> </AssignMessage>

ServiceCallout:

<ServiceCallout name="API-V1-InitializeAPI"> <Request variable="API-V1-Request"/> <Timeout>300000</Timeout> <Response>InitializeAPIResponse</Response> <HTTPTargetConnection> <URL>http://api.art.com/ECommerceAPI.svc/jsonp/InitializeAPI</URL> </HTTPTargetConnection> </ServiceCallout>

ExtractVariablesPolicy:

<ExtractVariables name="API-V1-Response"> <Source>InitializeAPIResponse</Source> <VariablePrefix>intializeresponse</VariablePrefix> <JSONPayload> <Variable name="CustomerZoneID"> <JSONPath>$.d.CustomerZoneID</JSONPath> </Variable> <Variable name="CurrencyCode"> <JSONPath>$.d.IsoCurrencyCode</JSONPath> </Variable> </JSONPayload> </ExtractVariables>

AssignMessagePolicyto service B:

<AssignMessage name="Products-V2-Request"> <Remove> <QueryParams> <QueryParam name="apiKey"/> <QueryParam name="applicationId"/> <QueryParam name="twoDigitISOCountryCode"/> <QueryParam name="twoDigitISOLanguageCode"/> </QueryParams> </Remove> <Set> <QueryParams> <QueryParam name="customerZoneId">{intializeresponse.CustomerZoneID}</QueryParam> </QueryParams> </Set> </AssignMessage>

Proxy Endpoints:

PreFlow:

<PreFlow name="PreFlow"> <Request> <Step> <Name>API-V1-Request</Name> </Step> <Step> <Name>API-V1-InitializeAPI</Name> </Step> <Step> <Name>API-V1-Response</Name> </Step> <Step> <Name>Products-V2-Request</Name> </Step> <Step> <Condition>request.verb equals "GET" and proxy.pathsuffix MatchesPath "/Products/*"</Condition> <Name>ValidateOAuth</Name> </Step> </Request> <Response/> </PreFlow>

Solved Solved
0 6 1,152
1 ACCEPTED SOLUTION

Not applicable

@Sagar Mummidivarapu

Your Service Callout should be using the value of the AssignTo from of the AssignMessage not the name of the policy.

You have: <Request variable="API-V1-Request"/>.

Should be: <Request variable="InitializeAPIRequest">

View solution in original post

6 REPLIES 6

Not applicable

Hi Sagar,

I've sent my query param is the service callout policy itself in some of my samples, and that worked for me in the past:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout enabled="true" continueOnError="false" async="false" name="API-V1-InitializeAPI">
    <DisplayName>API-V1-InitializeAPI</DisplayName>
    <FaultRules/>
    <Properties/>
    <Request variable="API-V1-Request"/>
    <Response>InitializeAPIResponse</Response>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://URL?foo={bar}</URL>
    </HTTPTargetConnection>
</ServiceCallout>


Not applicable

@Sagar Mummidivarapu

Your Service Callout should be using the value of the AssignTo from of the AssignMessage not the name of the policy.

You have: <Request variable="API-V1-Request"/>.

Should be: <Request variable="InitializeAPIRequest">

It worked like a gem. How to get the final response from service B? Now the service A issue is resolved but service B is successful but the response(supposed to be json document) is not shown. What should I do?

Once you get the response back from Service B, presumably in "ProductsResponse" message (note that I just faked the second service callout target):

<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-2">
    <DisplayName>Service Callout-2</DisplayName>
    <Request variable="ProductsRequest"/>
    <Timeout>300000</Timeout>
    <Response>ProductsResponse</Response>
    <HTTPTargetConnection>
        <URL>http://api.art.com/ECommerceAPI.svc/jsonp/InitializeAPI</URL>
    </HTTPTargetConnection>
</ServiceCallout>

you simply assign that to the "response" message using a final Assign Message.

<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-3">
    <DisplayName>Assign Message-3</DisplayName>
    <Properties/>
    <Copy source="ProductsResponse"/>
    <Set>
        <Headers>
            <Header name="kurt-was-here">{system.time}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Note the AssignTo type is "response".

There is only one external service call and hence one service call out should be there and its response is used for the real request api call from client. I don't want to use two service call outs. Does it makes sense?

I think so, you mentioned Service A then Service B so I prototyped as a "No Target" API with 2 Service Callouts.

If your using a "Reverse Proxy" API with one or more target endpoints, then each conditional flow would need to use an Assign Message with AssignTo of type "request".

<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-products">
    <DisplayName>Assign Message-products</DisplayName>
    <AssignVariable>
        <Name>this.CustomerZoneID</Name>
        <Ref>intializeresponse.CustomerZoneID</Ref>
        <Value>ZZ</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>this.CurrencyCode</Name>
        <Ref>intializeresponse.CurrencyCode</Ref>
        <Value>CC</Value>
    </AssignVariable>
    <Set>
        <QueryParams>
            <QueryParam name="customerZoneId">{this.CustomerZoneID}</QueryParam>
            <QueryParam name="currencyCode">{this.CurrencyCode}</QueryParam>
        </QueryParams>
        <Verb>GET</Verb>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

That also assumes your proxy endpoint (e.g. products) is also available as a backend endpoint for the TargetURL.

In any case, the secret is connecting the Service Callout request and response messages with the Extract Variables and Assign Message policies.