KVM is not updating the values

Not applicable
Hi, I have created one sample KVM to set the incremented values but it looks like it is always taking the initial values even through I'm using override="true" in KVM put. Expected functionality is, KVM will have the updated/incremented value from Java script after setting it into context. Not sure where I'm doing wrong. Please find the attached sample for the reference and help me out fixing this. Thanks!
Solved Solved
2 3 587
1 ACCEPTED SOLUTION

Thank for the question, and the code. I see you've got a couple problems in that API Proxy. For one thing, the order of policies you ran was:

JavaScript-1 putUrl getUrl

The Javascript was the thing that incremented the value. But it was starting from zero always, so it always incremented 0, resulting in a 1. The KVM PUT then stored the value 1, and the KVM Get then retrieved the value of 1.

Running it again, the same thing happened. Always 1.

There were some other problems too. For example with the KVM operations - you were referring to a variable in the key parameter of urlencoding.requesturl.hashed. Like this:

<Parameter ref="urlencoding.requesturl.hashed"/> 

the ref="..." indicates that the parameter is a variable. But no such variable exists in the context.

Anyway, I've fixed up an API proxy that demonstrates the use of the KVM to store an incremented value for each additional request. Find it attached. To use it, deploy it to any Edge org + env. The invoke it like this:

curl -i http://ORG-ENV.apigee.net/1080-kvm/t1
you should see something like
{
  "status" : true,
  "numalerts" : "4"
}

...after the 4th invocation.

View solution in original post

3 REPLIES 3

Thank for the question, and the code. I see you've got a couple problems in that API Proxy. For one thing, the order of policies you ran was:

JavaScript-1 putUrl getUrl

The Javascript was the thing that incremented the value. But it was starting from zero always, so it always incremented 0, resulting in a 1. The KVM PUT then stored the value 1, and the KVM Get then retrieved the value of 1.

Running it again, the same thing happened. Always 1.

There were some other problems too. For example with the KVM operations - you were referring to a variable in the key parameter of urlencoding.requesturl.hashed. Like this:

<Parameter ref="urlencoding.requesturl.hashed"/> 

the ref="..." indicates that the parameter is a variable. But no such variable exists in the context.

Anyway, I've fixed up an API proxy that demonstrates the use of the KVM to store an incremented value for each additional request. Find it attached. To use it, deploy it to any Edge org + env. The invoke it like this:

curl -i http://ORG-ENV.apigee.net/1080-kvm/t1
you should see something like
{
  "status" : true,
  "numalerts" : "4"
}

...after the 4th invocation.

Thanks @Dino. It was very help full.

I have to assign two different values every time to a single key. Is it possible?

Ex: In the above example you have added "number of alerts" value to alertsCount key. I wanted to assign "alert current timestamp" value also to alertsCount key. How we can achieve this feature?

Key ----------------------------> Value

alertsCount ----------------------> numalerts, alertCurrentTimestamp.

I believe, we can achieve this by using delimiter or use two different keys.

Yes, there are two ways to do what you want.

The first way is to use the index attribute.

   <Get assignTo="numalerts" index='1'>

...This says that the first field in the KVM entry should go to numalerts. You can also specify index=2 and a different assignTo to get the second field.

The other way to accomplish what you want is to use a field delimiter, as you described, and to split the retrieved value after retrieval. If you are processing the value in Javascript, this is an easy thing to do.