Hi,
I'm trying to navigate a json message in order to extract an element's value using the Extract Variables policy but it seems doesn't work because the policy failed.
This is the json message:
{
"Header": {
"AbstractMessage": {
"DeviceRootID": "xxxxxx@gmail.com",
"CorrelationID": "xxxxxxxxxxxxxxxxxxxxxxx"
}
},
"ApartmentID": "xxxxxxxxxxxxxxxxxxx",
"isServiceAlreadyActive": null,
"UserScopes": [
"aaaaaaa",
"bbbbbb",
"xxxxxx"
],
"UserRoles": [
"uuuuuuuu"
]
}
and this is the policy configuration:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables name="getUserScopes" enabled="true" continueOnError="true" async="false">
<DisplayName>getUserScopes</DisplayName>
<JSONPayload>
<Variable name="userscopes">
<JSONPath>$.UserScopes</JSONPath>
</Variable>
</JSONPayload>
<Source clearPayload="false">ServiceCallout.response</Source>
</ExtractVariables>
I also noticed a strange behavior in this because if I delete the "Header" from the json message it works, otherwise it fails.
Can someone help me in this issue, please?
Any comments are appreciated.
Thanks,
Fabio
Can you add some details around the service callout policy? Is the Content-Type of the response application/json for sure? Could the edit you are making possibly be impacting that content-type header?
Assuming ServiceCallout.response has the actual response you mentioned and the Content-Type is application/json, the below policy should work
<ExtractVariables name="getUserScopes" continueOnError="true"> <DisplayName>getUserScopes</DisplayName> <JSONPayload> <Variable name="userscopes" type="nodeset"> <JSONPath>$.UserScopes</JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">ServiceCallout.response</Source> </ExtractVariables>
I have included type="nodeset" as its a JSONArray.
I am not sure how the "Header" can cause issue. Please try this and let me know if it works.
works for me.
$ curl -i https://ORGNAME-ENVNAME.apigee.net/fabio-1/t1 HTTP/1.1 200 OK Date: Wed, 15 Feb 2017 22:00:06 GMT Content-Type: application/json Content-Length: 79 Connection: keep-alive Server: Apigee Router { "foundScopes": ["aaaaaaa","bbbbbb","xxxxxx"], "timestamp" : "1487196006106" }
see attached for a working example proxy.
It's working fine for me as well. PFB snapshots of ExtractVariables & ServiceCallout policies.
ServiceCallout:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout async="false" continueOnError="false" enabled="true" name="SC-Call-To-Target"> <DisplayName>SC-Call-To-Target</DisplayName> <Properties/> <Request clearPayload="true" variable="myRequest"> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> </Request> <Response>response</Response> <HTTPTargetConnection> <Properties/> <URL>{targetURL}</URL> </HTTPTargetConnection> </ServiceCallout>
ExtractVariables (Source as "ServiceCallout.response" or "response"):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-fetch-values"> <DisplayName>EV-fetch-values</DisplayName> <Properties/> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Source clearPayload="false">ServiceCallout.response</Source> <JSONPayload> <Variable name="userscopes"> <JSONPath>$.UserScopes</JSONPath> </Variable> </JSONPayload> </ExtractVariables>
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |