bulk update of environment key value maps by javascript

I have key value map under environment, say with mapIdentifier "routing".

I have apiproxy which accepts post method with json payload of key value pair.

First, I am extracting the payload, then parsing them using javascript as below:

if(context.flow=="PROXY_REQ_FLOW"){
var payload = context.getVariable("envInfo");
var jsonObject = JSON.parse(payload);
var jsonObj = jsonObject[0];  // to get rid of extra list wrapper
    for (var i = 0; i < jsonObj.length; i++){
        var obj = jsonObj[i];
        print("key:" + obj.key);    
        print("value:" + obj.value);    
    }
}

I have keyvaluemapoperation policy which just update only one key-value pair.

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Set-Up-Key-Value-Map-Routing" mapIdentifier="routing">
    <DisplayName>Set Up Key Value Map Routing</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Put override="true">
        <Key>
            <Parameter ref="key"/>
        </Key>
        <Value ref="value"/>
    </Put>
    <Scope>environment</Scope>
</KeyValueMapOperations>

What is the best way to update/insert all key value pairs ? Is there any way to put this KeyValueMapOperations policy in loop of javascript?

0 3 622
3 REPLIES 3

Former Community Member
Not applicable

There are probably other ways to do it. One way I can think of is:

1: Create a proxy with just the KeyValue Map Policy

2: Use JavaScript to call that endpoint async (http://docs.apigee.com/api-services/reference/javascript-object-model) - look under "Making JavaScript callouts with httpClient".

Thanks @Srinandan Sridhar. That works, but it seems making lots of call.

Something like below is good:

http://docs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/environments/%7Benv_name%7D...

but that works only to create, while for update operation, it says deprecated.

http://docs.apigee.com/management/apis/put/organizations/%7Borg_name%7D/environments/%7Benv_name%7D/...

So, do we have some alternative for this deprecated service?

Hi @NiteshShrestha

Please check if your org is CPS enabled - You can check by following the steps mentioned here

If it is, then the API used to create KVM is here and to update, you can look here.

NOTE: You can create KVM at different levels, please look at the documentation and use the appropriate Update/Create Mgmt APIs for your use case.