Select multiple values from a key value map

I have a number of key value pairs (country name and code) in a key value map. My API is given a list of country codes to validate. I am trying to use KVM policy to fetch all the key values in one go for my query param validation. Is this possible? If yes then how? Your quick response would be greatly appreciated.

Solved Solved
0 8 1,648
1 ACCEPTED SOLUTION

@Mahammad Feroz ,

You can use Management API to retrieve all key value maps in a policy. For more details refer here. Its not the best way , but it's the only way i can think of now today. You need to make a call either using service callout policy or javascript policy. I would prefer later.

Cheers,

Anil Sagar

View solution in original post

8 REPLIES 8

Dear @Mahammad Feroz ,

Welcome to Apigee Community.

Yes, Its possible. When you don't specify index value while fetching the key value map using GET, all the values are sent by comma separated. You can split by comma in javascript policy and validate against your query param.

For Example,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="putUrl" mapIdentifier="urlMapper">
    <Scope>apiproxy</Scope>
    <Put override="true">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
        <Value>"Anil"</Value>
        <Value>"Sagar"</Value>
    </Put>
    <Get assignTo="urlencoding.shorturl">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
    </Get>
</KeyValueMapOperations>

urlencoding.shorturl has value "Anil, Sagar"

1139-screen-shot-2015-09-11-at-31028-pm.png

Cheers,

Anil Sagar

Thank you Anil for your prompt response. But my query is on fetching all the key value pairs defined in the KVM not a particular key like the example you have taken. Pls refer the below example. I am trying to fetch both the key value pairs using KVM policy. Is this possible?

For ex:

<Put>

<Key>

<Parameter ref="urlencoding.requesturl1"/>

</Key>

<Value>"Anil"</Value>

<Value>"Sagar"</Value>

<Key>

<Parameter ref="urlencoding.requesturl2"/>

</Key>

<Value>"Feroz"</Value>

<Value>"Mahammad"</Value>

</Put>

Thanks,

Feroz.

What do you mean by both the key value pairs ? Can you try with two different Put Tags ?

My query is on Get not on Put. I would like to get all the key value pairs instead of a particular key value. I mean from my earlier example I would like to Get both the keys: urlencoding.requesturl1 & urlencoding.requesturl2 in one go.

Check answer i have posted recently. There is a way to do same.

@Mahammad Feroz ,

You can use Management API to retrieve all key value maps in a policy. For more details refer here. Its not the best way , but it's the only way i can think of now today. You need to make a call either using service callout policy or javascript policy. I would prefer later.

Cheers,

Anil Sagar

We are currently using service callout policy with basic auth to fetch the KVM and store it in a variable and then using the same in Javascript for validating all the input query params. Thank you for your clarification.

@Mahammad Feroz , Awesome. Glad issue is resolved. You can also click on Accept link below answer that will help others looking for similar solution.