Links

Delete Task

Tags: #hubspot #sales #crm #engagements #task #snippet
Author: Alok Chilka
Description: This template will delete a task in HubSpot.

Input

Import libraries

from datetime import datetime, timedelta
import requests, math
import json
import naas

Setup HubSpot

👉 Starting November 30, 2022, HubSpot API keys no longer enable access to HubSpot APIs, so in Naas version 2.8.3 and above, you need create a private app and use the access token.
Enter Your Access Token
HS_ACCESS_TOKEN = naas.secret.get("HS_ACCESS_TOKEN") or "YOUR_HS_ACCESS_TOKEN"
Enter your task ID
task_id = 19996680052

Model

Function to get recent tasks

def delete_task(uid):
#set headers
headers = {
'Content-Type': "application/json",
"authorization": f"Bearer {HS_ACCESS_TOKEN}"
}
#check if tasks already exist
get_url = "https://api.hubapi.com/engagements/v1/engagements/"
get_res = requests.get(
url=f"{get_url}/{uid}",
headers=headers,
allow_redirects=False,
)
if get_res.status_code == 200:
print("Task found..Deleting")
#delete task
del_url = "http://api.hubapi.com/engagements/v1/engagements/"
# Post requests
res = requests.delete(
url=f"{url}/{uid}",
headers= headers,
params= params,
allow_redirects=False,
)
else:
print("Task not found. Unable to delete")

Output

Delete task

delete_task(task_id)