Share via

APIM Liquid fails with error

Edwin van de Burgt 11 Reputation points
2020-11-25T20:35:41.127+00:00

On our dev APIM instance, our Liquid template is working fine, but on test it fails doing a "| Downcase", with a very strange error:

"Liquid error: Object of type 'Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.Templates.JTokenDrop' cannot be converted to type 'System.String'."

Even Google can't find anything about JTokenDrop.

I've created a very simple test policy for a GET operation (Content-Type: application/json header required, otherwise it will never work):

<policies>
    <inbound>
        <set-body template="none">{ "A" : "Abc" }</set-body>
        <set-body template="liquid">
{ "Test": "{{body.A | Downcase}}", "test": "{{body.A | downcase}}" }
</set-body>
    </inbound>
    <backend />
    <outbound>
        <set-header name="Content-Type" exists-action="override">
            <value>application/json</value>
        </set-header>
        <set-body template="none">@(context.Request.Body.As<string>())</set-body>
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

On dev, it returns the expected { "Test": "abc", "test": "Abc" }, on test:
{
"Test": "Liquid error: Object of type 'Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.Templates.JTokenDrop' cannot be converted to type 'System.String'.",
"test": "Abc"
}

By the way, I know "downcase" is invalid, because the Liquid operations in APIM should start with a capital, so that one is essentially a no-op.

I already tried to get a fresh APIM instance by doing a trick*, but the issue remains...

I would like to have this issue resolved, of course, but also I would like to have a method to see on with "patch level" the APIM instances are, because I expect that that's the difference...

Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.