Hi All,
I have just started learning APIGEE. I have created a KVM table and updated the same. I want to change the first value of the code which is "sri" to "shree". Please find below my code and tell me what can be done to get the desired output:
<KeyValueMapOperations name="Key-Value-Map-Operations-1" mapIdentifier="kvm_1"> <DisplayName>Key Value Map Operations-1</DisplayName> <Properties/> <ExclusiveCache>false</ExclusiveCache> <ExpiryTimeInSecs>300</ExpiryTimeInSecs> <InitialEntries> <Entry> <Key> <Parameter>school</Parameter> </Key> <Value>Saint Fransis</Value> </Entry> <Entry> <Key> <Parameter>College</Parameter> </Key> <Value>sri</Value> <Value>Chaitanya</Value> </Entry> </InitialEntries> <Put override="true"> <Key> <Parameter ref="variable.containing.College" index="1"/> </Key> <Entry name="sri">Narayana</Entry> <Value>narayana</Value> </Put> <Delete> <Key> <Parameter>__$$_EDGE_KVM_EMPTY_KEY_$$__</Parameter> </Key> </Delete> <Scope>environment</Scope> </KeyValueMapOperations>
Solved! Go to Solution.
You can just edit in the UI & Change the value. Would you like to to update in the runtime using the policy ? Also, See how to update KVM in runtime here.
-------------------------------
Anil Sagar
You can read and update the KVM in two ways:
The first mechanism is what you'd normally do during setup, as a one-time action: Specify some key/value pairs in the KVM. As Anil said in his answer, if you want to update the first value stored for the key "College" to "Sri", then you can do it in the User Interface.
The second mechanism is done via the KeyValueMapOperations policy that can be embedded into any API Proxy. For example to update a value, you can use this:
<KeyValueMapOperations name='KVM-2' mapIdentifier='kvm_1'> <Scope>environment</Scope> <Put override='true'> <Key> <Parameter>College</Parameter> </Key> <Value>Shree</Value> <Value>Chaitanya</Value></Put> <ExpiryTimeInSecs>10</ExpiryTimeInSecs> </KeyValueMapOperations>
(It's a little counter-intuitive that you're storing a person's name under the key "College" )
I'd suggest that you avoid the use of the "InitialEntries" element inside the KVMO policy. The idea behind that element is to specify initial values if there are no values. To me, that's something you should specify during administrative setup actions. To my mind, It's not something that belongs in a runtime policy that gets executed within the context of a request.
That element is great for demonstration purposes, but it feels inappropriate in properly designed API Proxies.
You can just edit in the UI & Change the value. Would you like to to update in the runtime using the policy ? Also, See how to update KVM in runtime here.
-------------------------------
Anil Sagar
Hi,
Please tell me how can i do that in the kvm code. I dont want to edit it in UI. I want a code using KVM where i can update this in runtime by using "request.queryparam.kvmvalue". Can you kindly let me know if that is possible by changing the code mentioned above. I dont want to do that by using <Value> which is seems to me like hardcoding.
Thanks in advance.
You can read and update the KVM in two ways:
The first mechanism is what you'd normally do during setup, as a one-time action: Specify some key/value pairs in the KVM. As Anil said in his answer, if you want to update the first value stored for the key "College" to "Sri", then you can do it in the User Interface.
The second mechanism is done via the KeyValueMapOperations policy that can be embedded into any API Proxy. For example to update a value, you can use this:
<KeyValueMapOperations name='KVM-2' mapIdentifier='kvm_1'> <Scope>environment</Scope> <Put override='true'> <Key> <Parameter>College</Parameter> </Key> <Value>Shree</Value> <Value>Chaitanya</Value></Put> <ExpiryTimeInSecs>10</ExpiryTimeInSecs> </KeyValueMapOperations>
(It's a little counter-intuitive that you're storing a person's name under the key "College" )
I'd suggest that you avoid the use of the "InitialEntries" element inside the KVMO policy. The idea behind that element is to specify initial values if there are no values. To me, that's something you should specify during administrative setup actions. To my mind, It's not something that belongs in a runtime policy that gets executed within the context of a request.
That element is great for demonstration purposes, but it feels inappropriate in properly designed API Proxies.
Hi Rizwana
I guess you want to change the value at a particular index in a particular entry in KVM dynamically using queryparams.
You can use the following KVM policy for your scenario, I checked and it is working for me
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-1" mapIdentifier="kvm_1"> <DisplayName>Key Value Map Operations-1</DisplayName> <Get assignTo="myvar" index="2"> <Key> <Parameter ref="request.queryparam.var1"/> </Key> </Get> <Put override="true"> <Key> <Parameter ref="request.queryparam.var1"/> </Key> <Value ref="request.queryparam.var2"/> <Value ref="myvar"/> </Put> <Scope>environment</Scope> </KeyValueMapOperations>
To get the desired output, send the request in the following format
"your_proxy_url?var1=College&var2=Shree"
"var1" is the key here and "var2" is the updated value.
Remember, the above case only works if you already know the total values(seperated by comma) in the kvm entry.
In case ifyou don't know it, then use the following:
1. KVM policy to fetch the whole value in a new variable
2. Use Javascript policy to split the values and change any specific value you want and store it again in some variable.
3. KVM policy again to put the updated value in the KVM.
I hope this solves your problem. @Rizwana Begum
Your problem statement doesn't look like a real world problem, I guess you are just exploring the apigee functionalities.
Good Luck
Thanks Bhanu,
It is working fine
This code fully describes part of my dissertation. I think that everyone can understand this only after see this and understands that doing it yourself is very difficult. So go and see.
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |