How to Print the Distance Returned by Google API on Browser ?

Not applicable

I am trying to call the Google API thorough edge. I have done the following:

1. Created an API Proxy with Target Endpoint as https://maps.googleapis.com/maps/api/distancematrix

2. Associated Extract Variable and Assign Message Policy in order to parse the XML value returned and to assign it to the payload to be displayed on browser.

3. Code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1"> <DisplayName>Extract Variables 1</DisplayName> <VariablePrefix>fare</VariablePrefix> <XMLPayload> <Variable name="distance" type="string"> <XPath>/DistanceMatrixResponse/row/element/distance/text</XPath> </Variable> </XMLPayload> </ExtractVariables>

Here I am extracting the value of Text to distance.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1"> <DisplayName>Assign Message 1</DisplayName> <Copy source="response"> </Copy> <Add> <QueryParams> <QueryParam name="distance">{request.queryparam.distance}</QueryParam> </QueryParams> </Add> <Set> <Payload contentType="text/plain">distance = {distance}</Payload> </Set> </AssignMessage>

Here I am printing the same on Payload.

But I am getting error message "{"fault":{"faultstring":"Unresolved variable : distance","detail":{"errorcode":"messaging.runtime.UnresolvedVariable"}}}".

Can anyone please let me know, what wrong I am doing ?

Solved Solved
0 4 413
1 ACCEPTED SOLUTION

Not applicable

oh its not the XPath - it the variable prefix "fare" - so the variable shoud be fare.distance not just distance in you Assign message policy

View solution in original post

4 REPLIES 4

Not applicable

Policies seem fine. The reason for the error is the XPath may be incorrect. can you please paste the sample payload response from the target endpoint so that we can validate the XPath

I placed the info in the attachment.

Sorry, did not find any attachment

Not applicable

oh its not the XPath - it the variable prefix "fare" - so the variable shoud be fare.distance not just distance in you Assign message policy