Need assistance on request methods (platform V2.3)

Hi devs,

Greetings!

/api/v2/search/tickets?query="updated_at:>'2022-10-03' AND (status:2 OR status:3) AND cf_somecheckbox:null"

/api/v2/search/tickets?query="updated_at:>%272022-10-03%27%20AND%20(status:2%20OR%20status:3)%20AND%20cf_somecheckbox:null"

When I try to fetch these tickets using the invoke template

"getTickets": {
        "schema": {
            "method": "GET",
            "host": "<%= iparam.freshdeskSubdomain %>.freshdesk.com",
            "path": "<%= context.url %>",
            "headers": {
                "Authorization": "Basic <%= iparam.freshdeskEncodedApikey %>",
                "Content-Type": "application/json"
            }
        },
        "options": {
        }
    }

I’m getting the below error

{
  status: 400,
  headers: {},
  response: 'error while substituting templates.',
  errors: {},
  errorSource: 'APP',
  attempts: 1
}

and my invoke method

$request.invokeTemplate("getTickets", {
        context:{
          url
        }
      });

Can anyone plz help me out here?

Thank you.

Hi there!

Any updates on this?

Can you try the approach mentioned in this post:

Hi @kaustavdm ,

Thanks for your response.

But unfortunately, it didn’t work for me.

This is my URL:

https://sudomain.freshdesk.com/api/v2/search/tickets?query="updated_at:>%272022-10-03%27%20AND%20(status:2%20OR%20status:3)%20AND%20cf_somefield:null"

Can u please help me to frame one?

Thank you.

Hi @kaustavdm!

any updates?

The template will be the same as in the post I shared above. Just some properties will change.

config/requests.json:

  "getTickets": {
    "schema": {
      "method": "GET",
      "host": "<%= iparam.freshdeskSubdomain %>.freshdesk.com",
      "path": "/api/v2/search/tickets",
      "query": {
        "query": "\"updated_at:<%= context.updated_at %>%20AND%20(status:2%20OR%20status:3)%20AND%20cf_somefield:null\""
      },
      "headers": {
        "Authorization": "Basic <%= iparam.freshdeskEncodedApikey %>",
        "Content-Type": "application/json"
      }
    }
  },

server/server.js:

await $request.invokeTemplate("getTickets", {
  context: {
    updated_at: timestamp
  }
});

The key changes are:

  1. Moved the query string under the query.query property
  2. Passed the updated_at value as a context variable
  3. Enclosed query.query with extra quotes.

You can choose to modify how you pass the query.query. You might want to send the whole string as a context variable, and pass the entire query as URL encoded. In that case, you would use:

  "getTickets": {
    "schema": {
      "method": "GET",
      "host": "<%= iparam.freshdeskSubdomain %>.freshdesk.com",
      "path": "/api/v2/search/tickets",
      "query": {
        "query": "\"<%= context.query %>\""
      },
      "headers": {
        "Authorization": "Basic <%= iparam.freshdeskEncodedApikey %>",
        "Content-Type": "application/json"
      }
    }
  },
$request.invokeTemplate("getTickets", {
  context: {
    query: encodeURI(query)
  }
});

Hi @kaustavdm,

Thanks for the swift response.

But I have already tried both methods, but no luck.

did you get the expected output?

the error I receive:

response: {"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"}]}

Thank you.

This is an error with the query validation failing. Not the entire request. I did not try this specific query, but the template works in other search URLs. Please test the query using Postman to see if you get a valid response. Once the query works, then you can use the same in the template.

Hi @kaustavdm,

Yes, initially I used a tool like Postman to construct the query.

It works just fine, but I couldn’t bring this into the request.json, that’s why I’m here.

Plz try this and provide me with a solution @kaustavdm.

Thank you.

@kaustavdm, any updates on this?

Can you share the Postman request in which the query worked? Either as a screenshot or exporting the request as cURL. The current issue is a matter of encoding that query correctly in the request template.

Sure!

Please help yourself.
FD.postman_collection.zip (682 Bytes)

Any progress, @kaustavdm?

have you figured it out?

Hey @Bene_Immanuel,

From the Postman collection shared -

curl --location 'https://subdomain.freshdesk.com/api/v2/search/tickets?query=%22updated_at%3A%3C%25272023-04-25%2527%2520AND%2520(status%3A2%2520OR%2520status%3A3)%2520AND%2520cf_checkbox_field%3Anull%22' \
--header 'Authorization: Basic authkey'

Does this schema help you?

"getTickets": {
    "schema": {
      "method": "GET",
      "host": "<%= iparam. freshdeskSubdomain %>.freshdesk.com",
      "path": "/api/v2/search/tickets",
      "query": {
        "query": "<%= context.query %>"
      },
      "headers": {
        "Authorization": "Basic <%= iparam.freshdeskEncodedApikey %>",
        "Content-Type": "application/json"
      }
    }
  }

And it would be invoked as -

const updatedDate = "2023-04-25"
const query = `updated_at:<'${updatedDate}' AND (status:2 OR status:3) AND cf_checkbox_field:null`

$request.invokeTemplate("getTickets", {
  context: {
    query: encodeURI(query)
  }
});

Hi @zach_jones_noel,

well still not working!

Still receiving the below error!

response: {"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"}]},

Hey @Bene_Immanuel

Please try the below approach -

request.json

"getTickets": {
    "schema": {
      "method": "GET",
      "host": "<%= iparam. freshdeskSubdomain %>.freshdesk.com",
      "path": "/api/v2/search/tickets",
      "query": {
        "query": "\"<%= context.query %>\""
      },
      "headers": {
        "Authorization": "Basic <%= iparam.freshdeskEncodedApikey %>",
        "Content-Type": "application/json"
      }
    }
  }

And app invoking the template as

const queryString = `updated_at:<'2023-04-25' AND (status:2 OR status:3) AND cf_checkbox_field:null`

$request.invokeTemplate("getTickets", {
  context: {
    query: queryString
  }
});

Let me know if this helps.

Thank you @zach_jones_noel

Will try and let you know.

Thank you @zach_jones_noel

I can get 200 response now.

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.