Recent searches


No recent searches

Request API search based on ticket custom fields date range



Posted Mar 13, 2024

I'm developing an application that allows users to select dates and insert them into custom fields. My goal is to utilize the Zendesk API to search for tickets based on specific start and end dates, which are represented as custom fields within the tickets. Here's an example of the URL I'm trying for the search query:

https://<domain>.zendesk.com/api/v2/search.json?query=type:ticket custom_field_16896528598683>=2024-04-21 custom_field_16896502734363<=2024-04-25

In this URL, custom_field_16896528598683 represents the start date and custom_field_16896502734363 represents the end date. My objective is to find tickets that either overlap or fall within the specified date range. The purpose of this search is to prevent the assignment of dates to a new ticket if another ticket already includes those dates, ensuring date uniqueness across tickets.
Is it possible to do? Or I need to search all tickets and pass one by one?


0

10

10 comments

image avatar

Tipene Hughes

Zendesk Developer Advocacy

Hey Vinicius,
 
Is this within the context of a ZAF app? If so, you could try getting the values using the client.get method e.g client.get('ticket.customField:custom_field_16896528598683'), saving the returned value to a variable and passing it in to the request.
 
Let me know if this works for you.
 
Tipene

0


Tipene Hughes, no, it's not.

It's related with API URL search.

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Thanks for the clarification. The API endpoint won't be able to directly parse a custom field name for the value. You'll need to provide the actual value as a parameter to the endpoint URL.

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Actually, scratch that. I've just done some additional testing and it appears that it might be able to work for your use case. Let me try a few extra things here and see what we end up with. 

0


Tipene Hughes, idk if I was clear enough.

Actually, I have a modal with a date selector, and after select those dates (the start date and the end date), I want to search if I have a ticket in conflict if these dates.

Example: Select 04/21 and 07/21, I want to see if I have a ticket with the same date in their custom fields using that URL I've sent.
The URL is not working, because I don't know if it's possible to search custom fields date with <= or >=, that was my question.

I already could solve the problem using tags and other custom fields. Tks!

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Thanks for the update. I've just done some testing on my end based on your example and it's working as expected. To answer your question, the <= and >= operators will work for your use case. Here's a link to the docs that go in to more detail. Is there any specific errors you're seeing returned when you make the request? Also, you're using the date field in your custom field, right?

0


Yes, I'm!

My ticket has this following object:

"custom_fields": [
{"id": 16896502734363,"value": "2024-04-17"},
{"id": 16896528598683,"value": "2024-04-15"}
]

And when I select dates where it can conflict, and try to search, it's not possible:
https://domain.zendesk.com/api/v2/search.json?query=type:ticket custom_field_16896528598683>=2024-04-16 custom_field_16896502734363<=2024-04-22

Or even when I try to intercept them:

https://domain.zendesk.com/api/v2/search.json?query=type:ticket custom_field_16896528598683>=2024-04-16 custom_field_16896528598683<=2024-04-22 custom_field_16896502734363<=2024-04-22 custom_field_16896502734363>=2024-04-16

Could you share your success test, please?

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Sure, here's an example test run in postman. I'll take a look at the logs and see if there is anything that stands out, as well.
 

0


Tipene Hughes, with the same dates it works (same if you use ":"), try to change your custom field date to 2024-03-20 and 2024-03-24, and do a request again, it won't work, even though the dates are in between those two of URL.

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

I've updated the dates and it's working as expected still.

Can you send me an example screenshot of the requests you're making?

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post