service call out gave no response to extract variable policy

Hi all ,

I made a service call out as below .

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="ExecuteDistanceRequest"> <Request variable="GeocodingRequest"/> <Response>GeocodingResponse</Response> <HTTPTargetConnection> <URL>https://mxyz</URL> </HTTPTargetConnection> </ServiceCallout>

Now when i use extract variable policy to get the data nothing gets assigned.

used extract policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables name="ParseGeocodingResponse"> <Source>GeocodingResponse</Source> <VariablePrefix>geocoderesponse</VariablePrefix> <JSONPayload> <Variable name="origin_addresses" type="array"> <JSONPath>$.origin_addresses</JSONPath> </Variable> <Variable name="destination_addresses" type="array"> <JSONPath>$.destination_addresses</JSONPath> </Variable> <Variable name="distance"> <JSONPath>$.rows[0].elements[0].distance.text</JSONPath> </Variable> <Variable name="duration"> <JSONPath>$.rows[0].elements[0].duration.text</JSONPath> </Variable> <Variable name="status"> <JSONPath>$.rows[0].elements[0].status</JSONPath> </Variable> </JSONPayload> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> </ExtractVariables>

Please suggest if i am missing anything.

Solved Solved
0 14 214
1 ACCEPTED SOLUTION

It seems the service callout is doing the same as your target invocation. Ie: invoking

https://maps.googleapis.com/maps/api/distancematrix/json?destinations=New%2BYork%2BCity%2CNY&origins... key}

In the first case, it's not correctly configured, but the target invocation does succeed (because you're passing the proxy request parameters which contain everything needed (destinations, origins, units, key)

If all you want to do is invoke this API once, just remove the service callout and move the ParseGeocodingResponse to the response (Make sure to use response as the source element and not the variable you were using before)

If however you want to do this as a service call out , you'll need to fix the way you're assigning the service callout request. Pay attention to the error returned in the service callout:

ServiceCallout.response { "destination_addresses" : [], "error_message" : "You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account", "origin_addresses" : [], "rows" : [], "status" : "REQUEST_DENIED" }

You're missing the key parameter in the callout request!

View solution in original post

14 REPLIES 14

First, your title "ServiceCallout gave no response to extract variables policy", I think is unfounded. It's not the case that the servicecallout did not "give" a response to extract variables. The way to think about it is, ServiceCallout will populate a variable with the contents of the HTTP response. I think Your desire is to use ExtractVariables to extract a subset of that response into additional context variables. So I suppose an appropriate title would be something like "My ExtractVariables policy is not extracting as I hoped it would"


The combination of ServiceCallout (SC) and a subsequent ExtractVariables (EV) is really common. Many customers use this and it works well. Why you would be seeing surprising results, is probably because the configuration for the respective policies is not synchronized. Not consistent.


Your ServiceCallout looks fine, I guess.

The EV policy you have will work with that SC policy, IF AND ONLY IF

  1. the response is a JSON type ( GeocodingResponse.header.content-type = "application/json" or similar)
  2. The response has elements named "origin_addresses" and "rows".
  3. The EV policy is attached in such a way that it executes after the ServiceCallout policy

Have you checked all that?

The one critical piece of information you haven't shared is the shape of the payload that is returned by the ServiceCallout. What does it look like?

Hi Dino ,

Thanks for your time

you are correct I wanted to extract the subset of the response,and use it to make another http call.

Here is the response format.

{
   "destination_addresses" : [ "New York, NY, USA" ],
   "origin_addresses" : [ "Washington, DC, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "228 mi",
                  "value" : 367436
               },
               "duration" : {
                  "text" : "3 hours 48 mins",
                  "value" : 13709
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

--------------------------
and here is the policy flow sequence.

    <Policies>
        <Policy>ExecuteDistanceRequest</Policy>---Assign message
        <Policy>GenerateGeocodingRequest</Policy>----service call out
        <Policy>ParseGeocodingResponse</Policy>----EV policy
    </Policies>
    <ProxyEndpoints>
        <ProxyEndpoint>default</ProxyEndpoint>
    </ProxyEndpoints>

-------------------------

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>GenerateGeocodingRequest</Name>
            </Step>
            <Step>
                <Name>ExecuteDistanceRequest</Name>
            </Step>
            <Step>
                <Name>ParseGeocodingResponse</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>


Your ExtractVariables policy looks fine against the JSON you provided. To double-check I've just tested your ExtractVariables policy against a manually hardcoded GeocodingResponse variable and it worked fine.

Can you attach a trace of your proxy?

if I put the extract policy in the response i am getting the values .

but i need to extract the value in preflow request flow only,

<PreFlow name="PreFlow">

<Request>

<Step> <Name>GenerateGeocodingRequest</Name> </Step>

<Step> <Name>ExecuteDistanceRequest</Name> </Step>

</Request>

<Response>

<Step> <Name>ParseGeocodingResponse</Name> </Step>

</Response>

It seems the service callout is doing the same as your target invocation. Ie: invoking

https://maps.googleapis.com/maps/api/distancematrix/json?destinations=New%2BYork%2BCity%2CNY&origins... key}

In the first case, it's not correctly configured, but the target invocation does succeed (because you're passing the proxy request parameters which contain everything needed (destinations, origins, units, key)

If all you want to do is invoke this API once, just remove the service callout and move the ParseGeocodingResponse to the response (Make sure to use response as the source element and not the variable you were using before)

If however you want to do this as a service call out , you'll need to fix the way you're assigning the service callout request. Pay attention to the error returned in the service callout:

ServiceCallout.response { "destination_addresses" : [], "error_message" : "You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account", "origin_addresses" : [], "rows" : [], "status" : "REQUEST_DENIED" }

You're missing the key parameter in the callout request!

Thank you very much , if we have multiple value in Jason response how can we assign it to extract variable

Your new question "how can we assign it to ExtractVariables"... doesn't make sense.

And maybe it is worth a new question, eh?

Nice sleuthing, Debora.

You deduced that it's not correctly configured by examining the Trace, is that right?

Of course I did. Trace is an API Developer's best tool in their toolbox