Can get ticket search API to work with new FDK9 request templates

With help from @zach_jones_noel and @Nadeem_Bhati I found the solution to this. It works if you add escaped double quotes either side of the context placeholder in the request template.

Shout out to @Ansfs91 who suggested the same solution but I missed that he had manually added encoded double quotes to the request template path in his solution when I tried, so thought it didn’t work. Apologies Albin.

NOTE: If you send the query string in the context object from the code with double quotes, even if encoded with encodeURI(), it will not work. You have to add the double quotes to the request template.

"searchTickets": {
    "schema": {
      "method": "GET",
      "host": "<%= context.subdomain %>.freshdesk.com",
      "path": "/api/v2/search/tickets",
      "headers": {
        "Authorization": "Basic <%= encode(context.apikey) %>"
      },
      "query":{
        "page": "<%= context.page %>",
        "query":"\"<%= context.queryString %>\""
      }
    },
    "options": {
      "retryDelay": 1500,
      "maxAttempts": 5
    }
  }

Call from code

context = {
  apikey: "you_apikey",
  subdomain: "your_subdomain",
  page: 1,
  queryString: "group_id:89000021686 AND created_at:>'2023-04-15' AND created_at:< '2023-04-06'"
 }

await client.request.invokeTemplate ('searchTickets',{context})

`

3 Likes