Delete HubSpot record
Category:
Custom-Coded Workflow Action,
Operations Pro/Ent
ETL:
Transform
Notes
Deleting a record might seem a little extreme but it's often necessary. This code snippet is a quick and easy way to handle that.
We'll often use this if we intend to replace a single record with two records. For example, if a husband and wife have been using a shared email address and we now have unique email addresses for both. Or if a custom object representing a timeslot needs to be turned into two timeslots now that someone has booked a slot in the middle.
Code
Language: JavaScript
const axios = require('axios');const accessToken = process.env.secretName;exports.main = async (event) =>let objectType = "contact";let objectId = "1234"; // You'll want to dynamically identify this valueconst headers = {'Authorization': `Bearer ${accessToken}`,'Content-Type': 'application/json'};const deleteUrl = `https://api.hubapi.com/crm/v3/objects/${objectType}/${objectId}`;axios.delete(deleteUrl, { headers: headers }).then(deleteResponse => {console.log('Delete Response:', deleteResponse.data);}).catch(deleteError => {console.error('Delete Error:', deleteError);});}}};
How can SpotDev support your business?
HubSpot Migrations
Move from Salesforce, Dynamics, Pipedrive or any CRM to HubSpot with SpotDev.
Learn moreHubSpot Integrations
Add advanced functionality to your HubSpot portal with API development services.
Learn moreRevOps
Align your sales, marketing and service teams to break down silos and trigger growth.
Learn more