Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Unable to Update Key-Value Map (KVM) after Capturing URL in Apigee Edge

Hello,

I have been trying to dynamically capture the URL of incoming requests and then update a Key-Value Map (KVM) in Apigee with that captured URL, but I'm encountering issues when attempting to update the KVM.

The Flow:

  1. Capture the Request URL in a JavaScript policy using:
    var endpoint = context.getVariable("request.url") || context.getVariable("proxy.basepath") + context.getVariable("proxy.pathsuffix");
     
  2. Generate a Unique KVM Key (timestamp-based):
    var requestLogKey = "log_" + new Date().getTime(); context.setVariable("kvm.key", requestLogKey);
  3. Use the KeyValueMapOperations Policy to update the KVM with the captured URL value.

The Problem:

While the URL is being captured successfully, when I try to update the KVM using the KeyValueMapOperations policy, the KVM is not being updated with the captured value. The logs show that the key is being created, but the value is not being updated.

I’m using the following approach to update the KVM:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="KVM-Update" mapIdentifier="TestABC">
<DisplayName>KVM Update</DisplayName>
<Description>Update KVM entries dynamically</Description>
<Key>
<Parameter ref="kvm.key"/> <!-- Captured Key -->
</Key>
<Value>
<Parameter ref="kvm.logentryvalue"/> <!-- Captured URL Value -->
</Value>
<Put override="true"/> <!-- Ensure existing values are updated -->
</KeyValueMapOperations>

What I have tried:

  • Using JavaScript to capture the URL and generate a unique key.
  • Trying to update the KVM with the captured URL value using the KeyValueMapOperations policy.
  • Logs indicate that the key is being generated, but the value does not get updated in the KVM.

I would appreciate it if anyone could provide guidance on:

  1. Why the KVM value isn't being updated.
  2. If there’s anything I might be missing in the flow or setup.
Solved Solved
0 1 78
1 ACCEPTED SOLUTION

Possibly the values in the KVM may not permit slashes. Or colons.  ?

one way to avoid this problem is to encode the URL (base64 encode?) before inserting it into the KVM. Can you try that and see? 

Of course you would need to decode the value after retrieval, as well.  

There are functions available in the Message template that can help with this.  So you can do something like this:

<AssignMessage name="AM-Encode-Variable">
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>encoded_url</Name>
    <Template>{encodeBase64(extracted_url)}</Template>
  </AssignVariable>
</AssignMessage>

 

View solution in original post

1 REPLY 1

Possibly the values in the KVM may not permit slashes. Or colons.  ?

one way to avoid this problem is to encode the URL (base64 encode?) before inserting it into the KVM. Can you try that and see? 

Of course you would need to decode the value after retrieval, as well.  

There are functions available in the Message template that can help with this.  So you can do something like this:

<AssignMessage name="AM-Encode-Variable">
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>encoded_url</Name>
    <Template>{encodeBase64(extracted_url)}</Template>
  </AssignVariable>
</AssignMessage>