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! Go to Solution.
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
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
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
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |