Message Template errors on unresolved variable

Does anybody know if this is a bug with Apigee or a mistake in the documentation?

The docs say:

“Enclose variable names in curly braces { }. If the variable does not exist, an empty string is returned in the output”

source: https://cloud.google.com/apigee/docs/api-platform/reference/message-template-intro#use-curly-braces-to-denote-variables

However, the following throws an error (FCVariableResolutionFailed)

<FlowCallout name="FlowCallout-MySharedFlow">
    <Parameters>
        <Parameter name="into.my-shared-flow.param1">{a.variable-that-does-not-exist}</Parameter>
    </Parameters>
    <SharedFlowBundle>my-shared-flow-v0</SharedFlowBundle>
</FlowCallout>
1 Like

It seems like that IS a documentation bug.

Try including IgnoreUnresolvedVariables in the policy.

<FlowCallout name="FlowCallout-MySharedFlow">
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Parameters>
        <Parameter name="into.my-shared-flow.param1">{a.variable-that-does-not-exist}</Parameter>
    </Parameters>
    <SharedFlowBundle>my-shared-flow-v0</SharedFlowBundle>
</FlowCallout>
1 Like

Same issue, it seems has no effect with FlowCallout.

It seems the best solution is to use the firstnonnull message template function:

<FlowCallout name="FlowCallout-MySharedFlow">
    <Parameters>
        <Parameter name="into.my-shared-flow.param1">{firstnonnull(a.variable-that-does-not-exist,)}</Parameter>
    </Parameters>
    <SharedFlowBundle>my-shared-flow-v0</SharedFlowBundle>
</FlowCallout>
1 Like

Thanks for contributing that suggestion!

1 Like