Need to access KVM values in Javascript policy

I’m working on a Apigee x proxy setup. I need to construct a request body which will be used in a Service Call-out. 

I need to append a value from KVM to the request body that is being constructed on the JS policy. 

Can someone suggest me how to access KVM values in Javascript policy?

Solved Solved
0 2 355
1 ACCEPTED SOLUTION

There's no direct access to KVM entries via JavaScript, so you'll need to use a KVM policy to access the entries and assign to a variable.

 

<KeyValueMapOperations name="KV-log-config" mapIdentifier="my-kvm-name">
    <Get assignTo="my_kvm_variable" index="1">
        <Key>
            <Parameter>my_kvm_variable</Parameter>
        </Key>
    </Get>
 <Scope>environment</Scope>
</KeyValueMapOperations>

 

Then in your JavaScript add that variable to your request body.

 

var myKVMVariable = context.getVariable('my_kvm_variable');
var reqObject = {
    "myKVMVariable" : myKVMVariable,
...
};
context.setVariable("message.content", JSON.stringify(reqObject));            

 

Hope that's clear.

View solution in original post

2 REPLIES 2

There's no direct access to KVM entries via JavaScript, so you'll need to use a KVM policy to access the entries and assign to a variable.

 

<KeyValueMapOperations name="KV-log-config" mapIdentifier="my-kvm-name">
    <Get assignTo="my_kvm_variable" index="1">
        <Key>
            <Parameter>my_kvm_variable</Parameter>
        </Key>
    </Get>
 <Scope>environment</Scope>
</KeyValueMapOperations>

 

Then in your JavaScript add that variable to your request body.

 

var myKVMVariable = context.getVariable('my_kvm_variable');
var reqObject = {
    "myKVMVariable" : myKVMVariable,
...
};
context.setVariable("message.content", JSON.stringify(reqObject));            

 

Hope that's clear.

Thanks @kurtkanaskie that worked