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
In HubSpot, go to Automation > Workflows.
Click Create workflow.
Choose Contact-based > Blank workflow, name it, then click Next.
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.
Click Apply filter, test the criteria if needed, then click Save.
Step 2: Create a Private App in HubSpot
In a new tab, go to Settings > Integrations > Private Apps.
Click Create a private app.
Set the app name and description.
Select the necessary scopes (CRM objects > Contacts – read access).
Click Create app, then copy the Access Token for later.
Step 3: Add the SMS Action in Your Workflow
Back in the workflow editor, click the + button to add an action.
Choose Custom code from the action list.
In the Secrets section:
Click Choose a secret > Add secret
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
Remove the existing code block.
Make sure HubSpot Client v3 is selected.
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)
Click Test in the workflow.
Select a contact with a phone number and run the test.
If successful, you'll see "SUCCESS" in the output.
Step 5: Review and Publish
Click Review and publish.
Review enrolment, un-enrolment, and timing options.
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.]