Back to listing

Delete HubSpot record

Custom-Coded Workflow Action, Operations Pro/Ent



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. 



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 value
   const headers = {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json'
        const deleteUrl = `${objectType}/${objectId}`;
        axios.delete(deleteUrl, { headers: headers })
          .then(deleteResponse => {
          console.log('Delete Response:',;
          .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 more

HubSpot Integrations

Add advanced functionality to your HubSpot portal with API development services.

Learn more


Align your sales, marketing and service teams to break down silos and trigger growth.

Learn more