Escaping flow variable names

I am trying to access some flow variables that have a URL in the name and Apigee just won't resolve them. I'm guessing I need to escape some characters but I'm not 100% sure. I've tried escaping the colon and forward slashes but that doesn't seem to help. Here's my Assign Message policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Set-Headers">
    <DisplayName>AM Set Headers</DisplayName>
    <Properties/>
    <Set>
        <Headers>
            <Header name="X-Product">{apiproduct.name}</Header>
            <Header name="X-User-Id">{jwt.Verify-JWT.decoded.claim.http://example.com/user_id}</Header>
            <Header name="X-Roles">{jwt.Verify-JWT.decoded.claim.http://example.com/roles}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

And here is what I'm seeing as a result:

    "X-Product": "whiz-connect",
    "X-Roles": "{jwt.Verify-JWT.decoded.claim.http://example.com/roles}",
    "X-User-Id": "{jwt.Verify-JWT.decoded.claim.http://example.com/user_id}"

As you can see, the flow variable without a URL is resolving properly but the other 2 aren't (and even still have the curly braces). I've tried other jwt. variables that don't have a URL in the name and they resolve properly.

Solved Solved
2 3 373
1 ACCEPTED SOLUTION

Yes, the challenge is that the colon is a special character within the curly braces - it's the divider between the variable name and the "default value". Also there is an assumption (As you've observed) that "normal" variable names won't contain slashes.

But, you can work around those limitations, by using placeholder variables. Like this:

<AssignMessage name="AM-Set-Headers">
    <AssignVariable>
        <Name>placeholder1</Name>
        <Ref>jwt.Verify-JWT.decoded.claim.http://example.com/user_id</Ref>
    </AssignVariable>
    <AssignVariable>
        <Name>placeholder2</Name>
        <Ref>jwt.Verify-JWT.decoded.claim.http://example.com/roles</Ref>
    </AssignVariable>
    <Remove>
        <Headers/>
    </Remove>
    <Set>
        <Headers>
            <Header name="X-Product">{apiproduct.name:null}</Header>
            <Header name="X-User-Id">{placeholder1}</Header>
            <Header name="X-Roles">{placeholder2}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo>response</AssignTo>
</AssignMessage>
 

View solution in original post

3 REPLIES 3

Yes, the challenge is that the colon is a special character within the curly braces - it's the divider between the variable name and the "default value". Also there is an assumption (As you've observed) that "normal" variable names won't contain slashes.

But, you can work around those limitations, by using placeholder variables. Like this:

<AssignMessage name="AM-Set-Headers">
    <AssignVariable>
        <Name>placeholder1</Name>
        <Ref>jwt.Verify-JWT.decoded.claim.http://example.com/user_id</Ref>
    </AssignVariable>
    <AssignVariable>
        <Name>placeholder2</Name>
        <Ref>jwt.Verify-JWT.decoded.claim.http://example.com/roles</Ref>
    </AssignVariable>
    <Remove>
        <Headers/>
    </Remove>
    <Set>
        <Headers>
            <Header name="X-Product">{apiproduct.name:null}</Header>
            <Header name="X-User-Id">{placeholder1}</Header>
            <Header name="X-Roles">{placeholder2}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo>response</AssignTo>
</AssignMessage>
 

works well..thanks

Awesome. Thanks @Dino-at-Google. I'll read up on the default value things as well. I wasn't aware of that. Appreciate the education