Setting Global Variable in Apigee

Not applicable

Hi,

I have a usecase wherein I am supposed to set 2 global variables which has to be accessible for every proxy call any number of times and not just for a single proxy call.

1 6 1,910
6 REPLIES 6

Use Organization Key Value Maps for doing this. Read more here : http://apigee.com/docs/api/keyvalue-maps

@sarthak If I use <InitialEntries> in Key-Value Map, would it not be initialized with every proxy call.

I would want the values to be initialized just once. Having done that, I would want every proxy call to use those values.

But this won't work for objects that can't readily be represented as json objects (like a httpClient exchange object). How can an object be saved and accessed globally?

@Kevin Kohut , You need to serialize the JSON object & store it as a string. Access same & unserialize it to access object again. See examples in this post here. Keep us posted if any.

Not applicable

@DSX-Team

You can directly create your kvm at the environment level that can be used globally by retrieving it from the proxy level using GET KVM policy.

Example:-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<KeyValueMapOperations name="****" enabled="true" continueOnError="false" async="false" mapIdentifier="***">

<ExpiryTimeInSecs>***</ExpiryTimeInSecs>


<Get assignTo= "***" index="1">

<Key>

<Parameter>***</Parameter>

</Key>

</Get>

<Scope>environment</Scope>

</KeyValueMapOperations>

Not applicable

This is not working for me. It's still this the correct way to proceed? Setting a variable with key-value-policy and retrieving it in JS policy via context is not working. context.getVariable('name') in null.

Thank you!