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

Retrieve KVM using Variable Value

Hi, I'm hoping someone can guide me as I'm a little stuck 🙂

I have created a KVM called "targets" for each environment, this is published via the CICD in my edge.json. Testing this via the Google API, it retrieves the value I ask for. It contains the name of a server, and the value is the endpoint (which is a PSC endpoint).

In my target PreFlow, I use some Javascript to pull an identifier out of the cookie, which works, and it sets a variable called "server". I can see in the DEBUG trace working and being set successfully.

What I'm trying to do next, is match that to the value in the KVM, to assign it the relevant endpoint. So my KVM is called "targets" and the variable is called "server"

 

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KVM-Targets" mapIdentifier="targets">
  <DisplayName>KVM-Targets</DisplayName>
  <Properties/>
  <Get assignTo="targetUrl">
    <Key>
      <Parameter>server</Parameter>
    </Key>
    <Scope>environment</Scope>
  </Get>
</KeyValueMapOperations>

 

 

 

But i'm getting a "Unresolved variable : targetUrl" in the next step. It doesn't seem like its getting to it, I don't believe its a private KVM.

Any thoughts would be very welcome!

 

 

 

Solved Solved
1 1 682
1 ACCEPTED SOLUTION

Hey there!

Thanks for the really clear question. Your diagnosis is correct - targetUrl is not being set because the KVM Get is not finding anything.

I have a simple solution for you. 

In your Key/Parameter element, you need to specify the word (the variable name) server not as TEXT but as the value of the ref attribute.  

This 

<Key><Parameter ref="server"/></Key>

Not this 

<Key><Parameter>server</Parameter></Key>

This is documented and explained here:

https://cloud.google.com/apigee/docs/api-platform/reference/policies/key-value-map-operations-policy...

Also I suggest you insert a conditional raisefault step in your proxy to check if targetUrl is empty. The correction I suggested here will work for this case, but it's possible there will be other cases where the expected value is not present in the KVM and you'd like to send back a sane clear message to the caller in that case. 

Good luck! 

View solution in original post

1 REPLY 1

Hey there!

Thanks for the really clear question. Your diagnosis is correct - targetUrl is not being set because the KVM Get is not finding anything.

I have a simple solution for you. 

In your Key/Parameter element, you need to specify the word (the variable name) server not as TEXT but as the value of the ref attribute.  

This 

<Key><Parameter ref="server"/></Key>

Not this 

<Key><Parameter>server</Parameter></Key>

This is documented and explained here:

https://cloud.google.com/apigee/docs/api-platform/reference/policies/key-value-map-operations-policy...

Also I suggest you insert a conditional raisefault step in your proxy to check if targetUrl is empty. The correction I suggested here will work for this case, but it's possible there will be other cases where the expected value is not present in the KVM and you'd like to send back a sane clear message to the caller in that case. 

Good luck!