# check task inside ticket.

**URL:** <https://community.hubspot.com/t/check-task-inside-ticket/46373>\
**Category:** APIs & Integrations\
**Tags:** php\
**Created:** [November 3, 2021, 12:08am UTC](https://community.hubspot.com/t/check-task-inside-ticket/46373 "2021-11-03T00:08:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luizsilva](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/luizsilva/32/97852_2.png) [@luizsilva](https://community.hubspot.com/u/luizsilva)\
**Post date:** [November 3, 2021, 12:08am UTC](https://community.hubspot.com/t/check-task-inside-ticket/46373/1 "2021-11-03T00:08:13Z")

</div>

Hey guys.

I need a help.

I need to check if there is any open task inside any closed ticket.  
Hubspot doesn’t have a filter that works very well for this. So I thought about using the API.  
How would I do this query via API?

example:

- get all closed tickets.  
- check each ticket if there is any task that has not yet been completed.  
- If it exists, delete the task.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [November 3, 2021, 8:04pm UTC](https://community.hubspot.com/t/check-task-inside-ticket/46373/2 "2021-11-03T20:04:21Z")

</div>

Hi @luizsilva

Unfortunately, there are going to be a lot of calls that you need to make for this. When the new engagements endpoints are complete, this may be a bit easier with a batch method. But this is the way I see it now

1. use the [CRM search endpoint](https://developers.hubspot.com/docs/api/crm/search) to filter all tickets by pipeline stage

2. Take that array of ticket ids and then use the[Associations endpoint](https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview) to look for associated tasks

3. Take those associated tasks and use the [patch method on the engagements endpoint](https://legacydocs.hubspot.com/docs/methods/engagements/update_engagement-patch) to update the status to complete

For step one, you could set up [webhooks](https://developers.hubspot.com/docs/api/webhooks) to be triggered whenever a ticket has been moved to closed rather than having to poll the API from your app on schedule.

Always a chance that I have overthought or underthought this 🙃 so will tag in @JBeatty and @zaklein to correct me if I am wrong.

---

<div class="post-metadata">

**Author:** ![zaklein](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zaklein/32/44431_2.png) [@zaklein](https://community.hubspot.com/u/zaklein)\
**Post date:** [December 14, 2021, 3:52pm UTC](https://community.hubspot.com/t/check-task-inside-ticket/46373/3 "2021-12-14T15:52:08Z")

</div>

Hi @luizsilva

I agree with @dennisedson’s outlined approach.

To supplement a little, the [Engagements API V3](https://developers.hubspot.com/docs/api/crm/engagements) has recently been **beta** released, in addition to Engagements now being searchable via [CRM Search API](https://developers.hubspot.com/docs/api/crm/search) (subject to the aforementioned beta release). This may give you a couple more options.

Assuming you’re working with (many!) fewer than 10,000 records (the limit for paginating through CRM Search API results), you’ll probably want to start your process by searching for whichever object type has fewer records matching target search criteria in your HubSpot account (i.e. Tickets or Tasks), and then batch loop through associations using the record IDs returned in step 1, as @dennisedson mentioned.

If you’re working with \>10,000 records in step 1, you’ll likely have to use the List Ticket OR List Task API endpoints and paginate through the results.

I hope that helps.

All the best,

Zach
