Using KVM in target endpoint doesn't work.

Hey,

I got an API proxy with two target endpoints both with a shared variable like this. https://test-{env}.com and https://test1-{env}.com. It seems like for https://test-{env}.com it works but for my https://test1-{env}.com it doesn't work at all. I'm getting the error:

{
    "fault": {
        "faultstring": "The Service is temporarily unavailable",
        "detail": {
            "errorcode": "messaging.adaptors.http.flow.ServiceUnavailable"
        }
    }
}

My KeyValueMapOperation looks like this:

    <Get assignTo="env" index="1">
        <Key>
            <Parameter>environment</Parameter>
        </Key>
    </Get>

What am I doing wrong?

0 9 1,021
9 REPLIES 9

@Ben Yuen, the error you are seeing has nothing to do with KVMs. How did you determine the KVM is causing this issue?

Check the below docs for the common causes for this error https://docs.apigee.com/api-platform/troubleshoot/runtime/503-service-unavailable

Because instead of using https://test1-{env}.com and im hardcoding the environment into the {env} placeholder everything works.

I don't either think the KVM is causing the problem because if I'm watching the trace I can see that the placeholder get switched and also the other target endpoint I got works with the same variable.

Can you post your API proxy code, I can take a look

How much do you want when you're saying API proxy code? Is that everything?

Yes either the proxy bundle export or your target endpoint configuration and policies used

Do you think it got something with having a dash next to on each side of the variable?

@Ben Yuen

There is no issue with using the hyphen character. You need to use the Assign Template to substitute the variable in the target endpoint URL. Please check a related post here -

https://community.apigee.com/questions/64490/set-target-hostname-to-arbitrary-value-using-a-var.html...

Or you could use javascript to modify the target.url. Here is an example for your reference, where I have used javascript with mocktarget-{env}.apigee.net . In the same example if you give test-qa.com instead of http://mocktarget-qa.apigee.net/, you will see http 503, that's because Apigee is not able to connect to test-qa.com

trace-1552323332173.txt dynamictargets-rev3-2019-03-11.zip

Steps

1. Remove Key Value Map Operation Policy.

2. Add Key Value Map Operation Policy at Proxy End Point PreFlow (Add Policy by clicking on PreFlow).

3. In Value Map Operation Policy Assign value like this

<Get assignTo="myvalue"> <Key> <Parameter>kvmkeyname</Parameter> </Key> </Get>

4. Use {myvalue} anywhere where you want.

EXAMPLE

Navigate to admin=>Enviroments=>key value map
Select Enviroment test
Add key value map with name kvm_store1
Add key =targetpoint value=get

Now Add Policy Key Value Map Operation By Selecting PreFlow Of Proxy EndPoints

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-1" mapIdentifier="kvm_store1">
    <DisplayName>Key Value Map Operations-1</DisplayName>
    <Properties/>
    <Get assignTo="targetpoint">
        <Key>
            <Parameter>targetpoint</Parameter>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>


To Use Set Varible in target End Point


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>http://httpbin.org/{targetpoint}</URL>
    </HTTPTargetConnection>
</TargetEndpoint>