How to read a KVM at runtime using scope apiproxy.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-Test" mapIdentifier="ADFS">
    <DisplayName>Key Value Map Operations-Test</DisplayName>
    <!-- <ExclusiveCache>false</ExclusiveCache> -->
    <ExpiryTimeInSecs>1800</ExpiryTimeInSecs>
    <Get assignTo="my_clientID">
        <Key>
            <Parameter>clientID</Parameter>
        </Key>
    </Get>
    <Scope>apiproxy</Scope>
    <!--<Scope>environment</Scope>-->
</KeyValueMapOperations>

 

I am trying to read KVM using <scope>apiproxy</scope>

But I am able to read the KVM's if I use <scope>environment</scope>

I am not sure if while setting up KVM's we have any option to configure scope environment vs apiproxy?

Thanks in advance!

 

0 3 174
3 REPLIES 3

Hi there,

It sounds to me like you created an Environment-level KVM instead of an API-level KVM. Here's a quote from the KeyValueMapOperations policy documentation; "Note that when accessing a map or map entry, you must specify the same scope value you used when the map was created. For example, if the map was created with a scope of apiproxy, you must use the apiproxy scope when retrieving its values, putting changes, or deleting entries."

The API-level KVM must be created through the use of an API request like this:

curl --request POST \
  'https://apigee.googleapis.com/v1/organizations/[YOUR_ORGANIZATION]/apis/[YOUR-API-PROXY]/keyvaluemaps?key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"name":"[YOUR_KVM_NAME]"}' \
  --compressed

After populating the KVM with entries you should have no issue accessing them using a KeyValueMapOperations policy with the apiproxy Scope as shown in your question.

 

Here's how I create a proxy-scoped KVM , and then insert an entry.

# Apigee X/hybrid
# Create map
curl -i -X POST $mgmtserver/v1/organizations/$ORG/apis/$PROXY/keyvaluemaps \
 -H "Authorization: Bearer $TOKEN" \
 -H 'content-type:application/json' \
 -d '{ "name": "map1" }'

# load one entry
curl -i -X POST $mgmtserver/v1/organizations/$ORG/apis/$PROXY/keyvaluemaps/map1/entries \
 -H "Authorization: Bearer $TOKEN" \
 -H 'content-type:application/json' \
 -d '{
      "name": "key1",
      "value" : "proxy-scoped-value"
    }'

I would like to add that this feature is finally available also on Hybrid from 1.8 😊