Question

Delete close ticket based on creation date

  • 28 September 2022
  • 1 reply
  • 52 views

Userlevel 1
Badge +2

I am currently working on the creation of a custom app which has a feature to delete single tickets after a certain time, since ticket was created, and only for close tickets. I want somehow to include the following automation that I have in place into the custom app,

Now I are facing the issue that in the API documentation we only can filter tickets based on creation date, but we don’t know when the ticket was created so we can not setup a date to start checking and comparing. We want to have something similar as the automation. Which API request should we use?


1 reply

Userlevel 4
Badge +12

Hi @sgutierrez 

 

You can use the Filter Tickets API to filter for tickets in closed status. The API response will include ‘created_at’ as one of the parameters, using which you can build the logic to delete tickets that match the criteria.

Request:

curl -v -u yourapikey:X -X GET 'https://domain.freshdesk.com/api/v2/search/tickets?query="status:5"'


Response:
 

{ "total":49, "results":[ { "cc_emails":["clark.kent@kryptonspace.com"], "fwd_emails":[ ], "reply_cc_emails":[ ], "fr_escalated":false, "spam":false, "email_config_id":17, "group_id":156, "priority":3, "requester_id":6007738334, "responder_id":6001263404, "source":2, "company_id":2, "status":2, "subject":"Sample Title", "to_emails":null, "product_id":null, "id":47, "type":null, "due_by":"2016-02-23T16:00:00Z", "fr_due_by":"2016-02-22T17:00:00Z", "is_escalated":true, "description":"<div>Sample description</div>", "description_text":"Sample description", "created_at":"2016-02-20T09:16:58Z", "updated_at":"2016-02-23T16:14:57Z", "custom_fields":{ "sector_no":7, "locked":true } }, { "cc_emails":["bruce.wayne@gothamdomain.com"], "fwd_emails":[ ], "reply_cc_emails":[ ], "fr_escalated":true, "spam":false, "email_config_id":44, "group_id":65, "priority":3, "requester_id":6007738334, "responder_id":6001263404, "source":2, "company_id":33, "status":2, "subject":"New Title", "to_emails":null, "product_id":null, "id":57, "type":null, "due_by":"2016-02-23T16:00:00Z", "fr_due_by":"2016-02-22T17:00:00Z", "is_escalated":true, "description":"<div>New description</div>", "description_text":"New description", "created_at":"2016-02-20T16:15:10Z", "updated_at":"2016-03-14T15:58:13Z", "custom_fields":{ "sector_no":8, "locked":true } }, ... ... ... ... ] }


Alternatively, you can use the ‘updated_since’ param to filter for tickets that have been created/updated after the set date. 

 

curl -v -u yourapikey:X -X GET 'https://domain.freshdesk.com/api/v2/tickets?updated_since=2015-08-17'

 

Cheers!

Reply