Filter api is not reliable

Hi Team,

I need assistance with filtering tickets based on a custom field. I’ve been using the Ticket Filter API to achieve this, but unfortunately, I haven’t been getting the expected output. I then tried the alternative method suggested in the documentation using the “custom_string” parameter in the filter, but it doesn’t seem to be reliable. Sometimes, I receive an empty array response even though the ticket still exists.

Here are the commands I’ve been using:

For filtering based on the custom field “cf_d_cid” with the value “3811196019”:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query="cf_d_cid: '3811196019'"

For filtering based on the custom field with the value “finance”:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query="custom_string: 3811196019"'

I would appreciate it if you could kindly assist me in finding a reliable solution to proceed further. Thank you.

Whereas, the ticket filter API, using a custom string, is taking much time to fetch the ticket data. For example, there is a maximum delay of 25 seconds to get the result from the time of ticket creation.

It’s not stable, as the delay varies between 12 to 25 seconds when fetching the filtered ticket details for newly created tickets.

I understand the issue you are facing with the ticket filter API and the delay in fetching the filtered ticket details. This inconsistency and delay in response are certainly concerning. Let me suggest a workaround that might help in achieving a more reliable and faster result.

Instead of using the ticket filter API, you can try using the “list_all_tickets” API and then filter the tickets locally using your preferred programming language or script. This approach allows you to have more control over the filtering process and can potentially provide a more stable and quicker response.

Here’s an example of how you can modify your approach:

  1. Use the “list_all_tickets” API to fetch all the tickets:

    curl -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/tickets'
    
  2. Filter the tickets locally based on your custom field using your preferred programming or scripting language. This gives you more flexibility in handling the filtering process.

By using this approach, you can bypass

But here, another hurdle arises.

As you mentioned, to fetch all tickets and then internally filter them. If I fail to get my filtered contact in the first search, I need to loop through the next pages until I find the exact match.

Instead of a single API call, I am forced to make multiple calls and traverse the pages until I find the exact match.

Just I need one of the above two APIs to work for me as expected. It would be better if the normal filter ticket with custom field works.

I understand your concerns about the additional complexity and effort required to loop through multiple pages when fetching all tickets and filtering them locally. In that case, let’s focus on troubleshooting and finding a solution for the ticket filter API with the custom field.

To address the issue of empty responses and the delay in fetching the filtered ticket details, I suggest the following steps:

  1. Check the syntax of your API queries to ensure they are correctly formatted. Make sure there are no syntax errors or incorrect values in the query parameters.

  2. Verify that the custom field name and value you are using in the query exactly match the ones set in your Freshdesk account. Any discrepancies in the naming or values can result in empty responses.

  3. Double-check the authentication and access permissions associated with your API key. Ensure that the API key has the necessary permissions to read the tickets and access the custom fields.

  4. Review the Freshdesk API documentation and any specific guidelines or limitations mentioned for the ticket filter API. It’s possible

So, you can check that this is the API that I am using to filter the tickets based on the custom field, as mentioned in the documentation.

For filtering based on the custom field “cf_d_cid” with the value “3811196019”:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query="cf_d_cid: '3811196019'"

OUTPUT:

{
    "results": [],
    "total": 0
}

Screenshot for the ticket with that field in freshdesk: D_ID: 3811196019

Thank you for providing the API query and the screenshot. Based on the information you provided, it seems that your API query syntax is incomplete. The issue might lie in the way you are passing the custom field value in the query.

To correct this, please modify your API query as follows:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query=cf_d_cid:3811196019'

Note that the value should not be enclosed in quotes in the query. Make sure to remove the extra double quotes (“”) around the custom field name and value.

Once you make this change, try running the API query again and check if you receive the expected results.

As per the documentation, quotes should be added.

Without quotes, it’s getting an error which I have shared below.

{
    "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 apologize for the confusion. You are correct that the quotes need to be added as per the documentation. However, it seems that there might be an issue with the formatting of the query parameters.

To address the error you received, I suggest modifying the API query as follows:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query=\"cf_d_cid:'3811196019'\"'

In this query, the entire query string is enclosed in double quotes, and within that, the custom field name and value are enclosed in single quotes. Make sure to escape the double quotes within the query parameter by adding a backslash () before them.

Please try running the modified API query and check if it returns the expected results without any validation errors.

The same error populates back:

{
    "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 apologize for the confusion. It seems that the issue lies with the query syntax that is being used. Let’s try a different approach to filter tickets based on the custom field.

Instead of using the search API endpoint, you can try using the filters API endpoint to retrieve tickets based on a specific custom field value. Here’s an example of how you can modify the API query:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/tickets?cf_d_cid=3811196019'

In this query, cf_d_cid is the name of the custom field and 3811196019 is the desired value you want to filter on.

Please give this modified API query a try and let me know if it returns the expected results without any validation errors.

Nope we can’t filter tickets in the list all ticket APIs using custom fields
ERROR:

{
    "description": "Validation failed",
    "errors": [
        {
            "field": "cf_d_cid",
            "message": "Unexpected/invalid field in request",
            "code": "invalid_field"
        }
    ]
}

I apologize for the confusion once again. You are correct that the list all ticket API doesn’t support filtering based on custom fields directly.

In that case, one approach you can take is to retrieve all the tickets using the list all tickets API and then filter the tickets locally based on the custom field values.

Here’s an example of how you can modify the API query:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/tickets'

This query will retrieve all the tickets. Once you have the tickets locally, you can filter them based on the custom field value you desire. You can iterate through the tickets and check the value of the custom field on each ticket to filter them.

Please let me know if you need any further assistance with this approach.

It’s already been discussed, and it was not advised, If I do not get an exact match in the search, I need to traverse the next page until I get the result, which leads to more API calls.

Can I get to connect with the support person?

I’m sorry for any inconvenience caused. Unfortunately, as an AI assistant, I don’t have the capability to connect you directly with a support person. However, I can try to assist you further with your question or problem.

If you would like to explore other possible solutions or alternatives to address the reliability issues with the Filter API, please let me know and I’ll do my best to assist you.

Just need to filter tickets based on a custom field
Custom field name : cf_d_cid
Custom field value: 3811196019

I apologize for any confusion earlier. If you want to filter tickets based on a custom field named “cf_d_cid” with the value “3811196019”, you can use the following query:

curl -v -u yourApiKey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query="cf_d_cid:3811196019"'

Make sure to replace yourApiKey with your actual API key and domain with your Freshdesk domain.

This query should return the tickets that match the specified custom field value. If you’re still experiencing issues with the API, it might be helpful to reach out to the Freshdesk support team for further assistance.

This is the one that is not working for me that’s why I raised the post on the community.

I apologize for the confusion. If you have already tried the suggested query and it is not working for you, it would be best to seek assistance from the Freshdesk community or support team.

They will have the knowledge and expertise to help you troubleshoot the issue and find a solution that works for your specific use case. Providing them with the specific details such as the API call you made and any error messages received will also help them understand the problem better and provide you with more accurate guidance.

Hello,

as per documentation, custom fields are not supported in queries. I suggest you to write a script to get all tickets and filter them.