Ticket Search Repsonds with 400 error with new fdk 9 and invokeTemplate

Context
The app provides a more advanced ticket dispatch method than what is offered natively by FreshDesk.

The issue
Since the required change to use InvokeTemplates, the app fails on the request to get current tickets for an agent when using the search parameter.

I have tried following the steps lined out in this similar issue with no avail:

Code being used:
server.js

let query = "agent_id:"+agent_id+" AND ((status:2 OR status:3 OR status:10) OR ((status:4 OR status:5) AND (created_at:>'"+week_start_closed+"')))";
          
//agent_id:36047799143 AND ((status:2 OR status:3 OR status:10) OR ((status:4 OR status:5) AND (created_at:>'2023-07-17')))
          

          $request.invokeTemplate('freshdeskTotals', {
            context: {
              'path': 'search/tickets/',
              'query': query
            }

requests.json

"freshdeskTotals": {
        "schema": {
            "method": "GET",
            "protocol": "https",
            "host": "tealium.freshdesk.com",
            "path": "/api/v2/<%= context.path %>",
            "headers": {
                "Authorization": "Basic <%= iparam.freshdesk_key %>",
                "Content-Type": "application/json"
            },
            "query": {
                "query": "\"<%= context.query %>\""
            }
        }

Looking at other similar issues reported here I have tried to add the escape on the " but this doesn’t seem to work. Annoyingly the code works absolutely fine when testing locally but fails when put live in our FreshDesk instance.

{
    "description": "Validation failed",
    "errors": [
        {
            "field": "query",
            "message": "Given query is invalid, expected format \"keyword:value OPERATOR keyword:'string' OPERATOR keyword:\"string\" OPERATOR keyword:>'yyyy-mm-dd' OPERATOR keyword:<integer\". Space is mandatory between key/value pair and operator. Please check the paranthesis if there are any.",
            "code": "invalid_value"
        }
    ]
}

I have also tested using temporal literals but that seems to fail on substituting the templates when testing locally.

When hard coding the query string into the requests.json file like so:

"freshdeskTotals": {
        "schema": {
            "method": "GET",
            "protocol": "https",
            "host": "tealium.freshdesk.com",
            "path": "/api/v2/<%= context.path %>",
            "headers": {
                "Authorization": "Basic <%= iparam.freshdesk_key %>",
                "Content-Type": "application/json"
            },
            "query": {
                "query": "\"agent_id:36047799143 AND ((status:2 OR status:3 OR status:10) OR ((status:4 OR status:5) AND (created_at:>'2023-07-17')))\""
            }
        }

The request within the app live within FreshDesk works successfully so I know it’s not an issue with the string that’s being generated. Copying that string and testing via Postman also provides that it works correctly.

It seems to be an issue with the requirement for this parameter to be encased in double quotes which is causing the issues for the template engine.

Hi @Simon_Browning. The dev team have to make an app ID specific fix for this work in the live environment

@zach_jones_noel @Saif - Guys we need to have a more permanent solution than a fix per App ID as more people are seeing it and spending valuable time trying to fix something they are never going to be able to work round. I know we can request the per App ID fix but I have been waiting for over a week for this to happen.

2 Likes