Key value Map operatons policy Not working

Not applicable

Hi,

I am creating KVM and then trying to access it and assign it to some other variable and then doing basic authentication. It's giving error as "steps.basicauthentication.UnresolvedVariable"

CreateKVM policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="createKVM" mapIdentifier="product"> <DisplayName>createKVM</DisplayName> <Put override="true"> <Key> <Parameter>productName</Parameter> </Key> <Value>Dell-laptop</Value> </Put> <Put override="true"> <Key> <Parameter>childProducts</Parameter> </Key> <Value>mouse</Value> <Value>headphones</Value> </Put> <Scope>apiproxy</Scope> </KeyValueMapOperations>

AccessKVM:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="accessKVM" mapIdentifier="product"> <DisplayName>accessKVM</DisplayName> <Get assignTo="productNameVal"> <Key> <Parameter ref="productName"/> </Key> </Get> <Scope>apiproxy</Scope> </KeyValueMapOperations>

Doing basic auth:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <BasicAuthentication name="auth_header" mapIdentifier="product"> <DisplayName>auth_header</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <User ref="productNameVal"/> <Password ref="productNameVal"/> <AssignTo createNew="false">request.header.Authorization</AssignTo> <Source>request.header.Authorization</Source> </BasicAuthentication>

Then checking if variable is set or not:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <RaiseFault async="false" continueOnError="false" enabled="true" name="checkVar"> <DisplayName>checkVar</DisplayName> <Properties/> <FaultResponse> <Set> <Headers/> <Payload contentType="text/plain">{productNameVal}</Payload> <StatusCode>500</StatusCode> <ReasonPhrase>Server Error</ReasonPhrase> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>

But in trace also, it is not assigning variable values and also not setting payload.

please let me know what's the issue in KVM policy.

Solved Solved
0 5 600
1 ACCEPTED SOLUTION

HI @zalak pathak

Can you confirm how you are populating the variable "productName" and what is the value ? Can you confirm if its "childProducts" ?

I changed the AccessKVM policy to

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="accessKVM" mapIdentifier="product">
    <DisplayName>accessKVM</DisplayName>
    <Get assignTo="productNameVal">
        <Key>
            <Parameter>childProducts</Parameter>
        </Key>
    </Get>
    <Scope>apiproxy</Scope>
</KeyValueMapOperations>

I was able to get the values (mouse, headphones)

Also in your BasicAuth policy, you can use the following code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication name="auth_header" async="false" continueOnError="false" enabled="true">
    <DisplayName>auth_header</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="productNameVal"/>
    <Password ref="productNameVal"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
</BasicAuthentication>

I was able to get Basic bW91c2UsaGVhZHBob25lczptb3VzZSxoZWFkcGhvbmVz

Probably you are not passing the right values to populate productName variable.

NOTE: Since you have more that one value for products in the KVM, if you want only one of the values, you can use index to get a particular one, see KVM docs

Hope this helps !!

View solution in original post

5 REPLIES 5

HI @zalak pathak

Can you confirm how you are populating the variable "productName" and what is the value ? Can you confirm if its "childProducts" ?

I changed the AccessKVM policy to

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="accessKVM" mapIdentifier="product">
    <DisplayName>accessKVM</DisplayName>
    <Get assignTo="productNameVal">
        <Key>
            <Parameter>childProducts</Parameter>
        </Key>
    </Get>
    <Scope>apiproxy</Scope>
</KeyValueMapOperations>

I was able to get the values (mouse, headphones)

Also in your BasicAuth policy, you can use the following code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication name="auth_header" async="false" continueOnError="false" enabled="true">
    <DisplayName>auth_header</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="productNameVal"/>
    <Password ref="productNameVal"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
</BasicAuthentication>

I was able to get Basic bW91c2UsaGVhZHBob25lczptb3VzZSxoZWFkcGhvbmVz

Probably you are not passing the right values to populate productName variable.

NOTE: Since you have more that one value for products in the KVM, if you want only one of the values, you can use index to get a particular one, see KVM docs

Hope this helps !!

Thanks @Sai Saran Vaidyanathan . I was using ref property considering that it is becoming variable. But i removed the ref property as it was parameter to parameter mapping. It worked.

@zalak pathak - Glad it worked !

@Sai Saran Vaidyanathan I was also having the same error but after I read your post my proxy is working fine now. Thank you!

@Sthembile Dladla - thats good to know. Glad you searched here to get your answer. Apigee community has so much useful info.

Please reach out if you have any questions.