Hi,
I am trying to develop an Apigee proxy using Edge where the request to the proxy is a Json body that looks something like
{
"Proxy":
[
{"name":"Proxy1", "Param1":false, "Param2":"false"},
{"name":"Proxy2", "Param1":true, "Param2":"false"}
{"name":"Proxy3", "Param1":false, "Param2":"true"},
{"name":"Proxy4", "Param1":true, "Param2":"true"}
........
{"name":"ProxyN", "Param1":true, "Param2":"true"}
]
}
And the proxy need to pick all the values from the Json body and update a KVM with name attribute to Key and Param1 and Param2 as respective value pairs. Like below.
KEY VALUE
Proxy1 false, false
Proxy2 true, false
Proxy3 false, true
Proxy4 true, true
......
ProxyN true, true
I am trying with extract variables but the values in Json are dynamic meaning there can be one entry or N entries. Can someone suggest how can I achieve this?
Thanks
Thanks for reaching out,
You can extract any component of the message. Including headers, URI paths, JSON/XML payloads, form parameters, and query parameters by using ab Extract Variables policy.
The policy works by applying a text pattern to the message content and, upon finding a match, sets a variable with the specified message content.
Please have look to thai document, here you will find more details:
https://cloud.google.com/apigee/docs/api-platform/reference/policies/extract-variables-policy
Hi @Hilda_Arteaga ,
Thank you for the response.
I have gone through the extractvariables policy. If in the use case I mentioned, if the Json body has fixed number of entries like one or 5 or 12 etc. then extractvariables policy might work. But in my case it is dynamic meaning in one request to my proxy the Json body may contain 4 entries and in the second request it may contain 50 entries.
So how can I extract them dynamically and my next step is to update KVM dynamically with these extracted entries like I quoted in my original question.
Is this something we can do using Apigee or this kind of dynamic loopings are not something we could achieve?
Thanks
Is this something we can do using Apigee or this kind of dynamic loopings are not something we could achieve?
You cannot configure the Apigee flow to loop dynamically.
The way I would handle this is, to re-imagine the data format. Instead of storing individual keys and values, store aggregated values as a full JSON, and then later use a dynamic JsonPath to extract the value of interest.
What I mean is, rather than storing multiple keys and distinct values, like this:
key | value |
treatment_code | ANQ |
authorization_level | 18 |
foreign_client_id | 298jlkdo3i03eokdl |
...you would store one data item, as JSON, like this;
key | value |
data | {"treatment_code" : "ANQ", "authorization_level": 18, "foreign_client_id": "298jlkdo3i03eokdl"} |
and then later you can use an assignmessage policy with an AssignVariable using a jsonpath expression in the Template to get what you want.
<AssignMessage name='AM-Extract-Setting'>
<!-- field-of-interest holds something like "treatment_code" or "authorization_level" -->
<!-- json_value_1 holds the JSON blob that has been read from KVM -->
<AssignVariable>
<Name>json_path_1</Name>
<Template>$.{field-of-interest}</Template>
</AssignVariable>
<AssignVariable>
<Name>field</Name>
<Value>BADDBEEF</Value>
<Template>{jsonPath(json_path_1,json_value_1)}</Template>
</AssignVariable>
</AssignMessage>