Hubspot custom code SMS integration

Updated 1 year ago

This tutorial will shows how to send automated SMS using ClickSend API using the Hubspot CRM. For troubleshooting purposes please contact our support team.


To get started you will need:

Configuring the trigger/s for the workflow

  1. Click on the "Automation" tab from the menu bar and open the "Workflows" in a new tab from the drpdown menu.

  2. Click on "Create workflow" button.

  3. To keep this guide simple we will select "Contact-based" blank workflow, you can select any trigger you like as long as it contains the phone number field. After selecting the trigger and naming the workflow click on the "Next" button.

  4. Click on the "Set up triggers" button and filter on how the contacts enter the workflow.

  5. For simplicity purposes we will filter contacts based on if the phone number field does not contain the alphabet 'a', so that we can select every contact. After setting up the filter click on the "Apply filter" button.

  6. If you want to cross check the filter setup click on "Test criteria" button. Click on "Save" button to save filter/s after the configuration.


Configuring the action for the workflow:

  1. Switch to the previous tab and click on the "Settings" icon.

  1. Click on "Private Apps" from the Settings menu and click on "Create a private app" button.

  1. Add the "Name" and "Description" for the app.

  1. Select the scopes as shown in the image and click on "Create app" button.

  1. Click and copy the token.

  1. Switch to workflows tab and click on the "+" button to add the action.

  2. Click on "Custom code" from the action list.

  3. Click on "Choose a secret" dropdown menu and select "Add secret" to add your Private app token.

  4. Type "HPKEY" as "Secret name" and paste the Private app token under the "Secret value". Click on "Save" button.

  5. We will need your ClickSend credentials to send SMS - ClickSend Credentials.
  6. Copy your username from the ClickSend dashboard and click on "Add secret".

  7. Type "CSUSERNAME" as "Secret name" and paste the username under the "Secret value". Click on "Save" button.

  8. Repeat the steps 8 and 9 to add your ClickSend API Key, use "CSKEY" as "Secret name" and API Key as "Secret value".

  9. Remove the existing code, then copy and paste the code from “Hubspot_CustomCode.js” in the “Code” section. Make sure Hubspot Client v3 is selected.

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

    exports.main = async (event, callback) => {

    try {
    let firstName;
    let phone;
    let lastName;
    const username = process.env.CSUSERNAME; // Your CS username via secret
    const key = process.env.CSKEY; /// Your CS apikey via secret

    const result = Buffer.from(username+":"+key).toString('base64');

    const hubspotClient = new hubspot.Client({"accessToken":process.env.HPKEY});
    const ApiResponse = await hubspotClient.crm.contacts.basicApi.getById(
    ['phone', 'firstname', 'lastname']
    phone =;
    firstName = (!=undefined) ? : '';
    lastName = (!=undefined)? : '';
    // You can GET more fields such as company, email, using the Husbspot API

    const message = 'Hi '+firstName+ ' '+'Hubspottesting'; // Add a custom message here

    var data = JSON.stringify({
    "messages": [
    "body": message,
    "to": phone,
    "from": "", // Add your Sender ID (Optional)

    var config = {
    method: 'post',
    url: '',
    headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Basic '+result
    data : data

    .then(function (response) {
    .catch(function (error) {
    } catch (err) {
    throw err;
    const email = event.inputFields['email'];
    const phone = event.inputFields['phone'];

    outputFields: {
    email: email,
    phone: phone,

  10. Change the content of message body as per the need. Click on the “Save” button after making the changes.

Testing (Optional)

  1. To test the action select a contact from the drop-down list and click on the "Test" button.

  2. The output should have a "SUCCESS" value.


Publishing the Workflow

  1. Click on "Review and publish" button.

  2. Review the Enrollment, Unenrollment and Timing options. Click on the "Turn on" button.

  3. The workflow will now automatically send the SMS whenever a contact triggers the workflow.

How Did We Do?

Powered by HelpDocs (opens in a new tab)