Skip to main content

Integration Guide: HubSpot

This guide shows you how to automatically send SMS messages from HubSpot using ClickSend and custom code actions in workflows.

Updated over 10 months ago

Prerequisites

Before you begin, you’ll need:

  • A ClickSend account

  • A HubSpot account

  • HubSpot Operations Hub Professional or higher – View plans


Step 1: Create a Workflow Trigger

  1. In HubSpot, go to Automation > Workflows.

  2. Click Create workflow.

  3. Choose Contact-based > Blank workflow, name it, then click Next.

  4. Click Set up triggers, then define how contacts enter the workflow.

    • Example: Use a filter like "Phone number does not contain 'a'" to include all valid phone numbers.

  5. Click Apply filter, test the criteria if needed, then click Save.


Step 2: Create a Private App in HubSpot

  1. In a new tab, go to Settings > Integrations > Private Apps.

  2. Click Create a private app.

  3. Set the app name and description.

  4. Select the necessary scopes (CRM objects > Contacts – read access).

  5. Click Create app, then copy the Access Token for later.


Step 3: Add the SMS Action in Your Workflow

  1. Back in the workflow editor, click the + button to add an action.

  2. Choose Custom code from the action list.

  3. In the Secrets section:

    1. Click Choose a secret > Add secret

    2. Add the following secrets:

      • HPKEY – Your HubSpot Private App Token

      • CSUSERNAME – Your ClickSend username (from dashboard)

      • CSKEY – Your ClickSend API key


Step 4: Add and Customise the Code

  1. Remove the existing code block.

  2. Make sure HubSpot Client v3 is selected.

  3. Copy and paste the following code:

const hubspot = require('@hubspot/api-client');
var axios = require('axios');

exports.main = async (event, callback) => {
try {
const username = process.env.CSUSERNAME;
const key = process.env.CSKEY;
const hubspotClient = new hubspot.Client({ accessToken: process.env.HPKEY });

const result = Buffer.from(`${username}:${key}`).toString('base64');
const contact = await hubspotClient.crm.contacts.basicApi.getById(
event.object.objectId,
['phone', 'firstname', 'lastname']
);

const phone = contact.body.properties.phone;
const firstName = contact.body.properties.firstname || '';
const lastName = contact.body.properties.lastname || '';
const message = `Hi ${firstName}, this is a test message from HubSpot.`; // Customize as needed

const data = JSON.stringify({
messages: [{
body: message,
to: phone,
from: "", // Optional: add Sender ID
source: "Hubspot"
}]
});

const config = {
method: 'post',
url: 'https://rest.clicksend.com/v3/sms/send',
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${result}`
},
data: data
};

await axios(config);
} catch (err) {
console.error(err);
throw err;
}

callback({
outputFields: {
email: event.inputFields['email'],
phone: event.inputFields['phone'],
},
});
};

4. Click Save.


Test Your Workflow (optional)

  1. Click Test in the workflow.

  2. Select a contact with a phone number and run the test.

  3. If successful, you'll see "SUCCESS" in the output.


Step 5: Review and Publish

  1. Click Review and publish.

  2. Review enrolment, un-enrolment, and timing options.

  3. Click Turn on to activate the workflow.


Done!

Your workflow is now live and will send an SMS via ClickSend each time a contact meets your trigger conditions.

For troubleshooting help, [contact our support team.]

Did this answer your question?