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.
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
For step one, you could set up 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.
To supplement a little, the Engagements API V3 has recently been beta released, in addition to Engagements now being searchable via CRM Search API (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.