Gabriel Guérin
Gabriel Guérin

Reputation: 468

HubSpot API — Automatically bulk delete tasks/contacts/deals (or anything) using Make

I would like to automatically bulk delete all tasks older than a month in HubSpot (we have more than 10,000 tasks!), instead of doing it one by one. I tried looking on the internet but it doesn’t seem that HubSpot has any functionalities like it. Thus, I tried to implement such scenario using Make (formerly Integromat) unsuccessfully.

Upvotes: 0

Views: 628

Answers (1)

Gabriel Guérin
Gabriel Guérin

Reputation: 468

Answering to my question for knowledge purposes.

I managed to create a scenario allowing me to automatically bulk delete tasks (or anything) based on a certain set of criteria using Make (formerly Integromat). I had to use HubSpot’s API and Flow Control tools to achieve such result.

The scenario looks like the following: Automatically bulk delete all tasks in HubSpot using a Make scenario overview

Module 1: API Call

Search for all tasks based on a certain set of criteria (here, all tasks created before the last 30 days).

If you wish to search for another object (such as contacts or deals), you can take a look at the CRM Search API for all available search requests. You can also browse through the Properties API to get a comprehensive list of available properties.

  • URL: /crm/v3/objects/tasks/search
  • Method: POST
  • Body:
    {
      "limit": "5",
      "properties": [
        "hs_task_subject",
        "hs_task_type",
        "hs_timestamp"
      ],
      "filterGroups": [
        {
          "filters": [
            {
              "propertyName": "hs_task_status",
              "operator": "EQ",
              "value": "NOT_STARTED"
            },
            {
              "propertyName": "hs_createdate",
              "operator": "LT",
              "value": "{{formatDate(addDays(now; -30); "x")}}"
            }
          ]
        }
      ]
    }

Module 2: Repeater

  • Initial Value: 0
  • Repeats: {{if(module1.body.total = null; 1; module1.body.total / 100)}} (if total is less than 100, do not repeat)
  • Step: {{ifempty(module1.body.paging.next.after; 100)}} (automatically sets it to the first module’s after value, otherwise to 100 if after value is empty)

You can find out more about properties and search limitations here and here. Basically, the repeater allows you to loop over all HubSpot pages.

Module 3: Sleep

Sleep module to prevent RateLimitError

Module 4: API Call

Same as Module 1, except that you must add an after parameter to include the repeater’s value.

+    "after": "{{module2.i}}"

Module 5: Iterator

Iterate over Module 4’s results array: {{module4.body.results}}.

Module 6: API Call

Delete tasks using the ID returned by the iterator.

{
   "inputs":[
      {
         "id":"{{module5.id}}"
      }
   ]
}

Voilà !

Upvotes: 0

Related Questions