Use any module within Operations Hub custom code /
empower you to work with a wider range of libraries.

02/10/2023

HubSpot's Operations Hub is a powerful platform for automating various tasks and actions. One of its key features is Custom Coded Actions, which allow users to run custom code within HubSpot. However, there are limitations on the libraries you can use in Custom Coded Actions, which can be restrictive. Enter HubSpot-OperationHub-cca-compiler, a tool designed to break through those limitations and empower you to work with a wider range of libraries.

What is HubSpot-OperationHub-cca-compiler?

HubSpot-OperationHub-cca-compiler is a local development tool that provides a framework for working on your Custom Coded Actions (CCAs) locally and executing them in the same context as HubSpot. With this tool, you can write your CCAs using the libraries you want, even if they are not officially supported by HubSpot.

Demo

Key Features

Here are some of the key features and benefits of HubSpot-OperationHub-cca-compiler:

1. Library Freedom

Want to create a Custom Coded Action to perform a specific task, like validating phone number formats? Instead of writing all the logic from scratch, you can look for open-source modules and libraries online. However, Custom Coded Actions don’t allow you to import external libraries directly. HubSpot-OperationHub-cca-compiler offers a solution to this limitation. You can install the libraries you need locally, and the tool will package everything into a single file that works seamlessly within HubSpot.

2. Easy Setup

Using HubSpot-OperationHub-cca-compiler is straightforward. Start by cloning the project and installing the necessary dependencies with a simple command:

git clone https://github.com/Antoinebr/HubSpot-OperationHub-cca-compiler.git
cd HubSpot-OperationHub-cca-compiler
npm install

Create a .env file with your private App Token, which should look like this:

privateAppToken = "your-private-app-token"

3. Project Initialization

To create a new Custom Coded Action project, you can use the following command:

npm run init <nameOfYourProject>

For example:

npm run init my-new-custom-coded-action

This command generates a template that contains a file named cca.js. This is where you write your custom code.

4. Code Your CCA

Inside cca.js, you can write your CCA logic. The template provides a clear structure for your code, making it easy to follow. Here’s an example of a CCA that formats phone numbers:

const format = require('@sturdynut/i18n-phone-formatter');

exports.main = async (event, callback) => {
    const phoneNumber = event.inputFields.phoneNumber;

    if (!phoneNumber) throw new Error('phoneNumber is not set, are you sure you put phoneNumber in the "properties to include in code"?');

    const countryCode = event.inputFields.countryCode;

    if (!countryCode) throw an Error('countryCode is not set, are you sure you put country in the "properties to include in code"?');

    const formattedNumber = format.formatE164(countryCode, phoneNumber);

    callback({
        outputFields: {
            formattedNumber
        }
    });
}

The event.js file represents the properties you can include in your code, making it easy to interact with the data.

5. Node Modules

You can install any node modules you require for your project. Install them with npm, and then use them within your code:

npm install @sturdynut/i18n-phone-formatter

And then add it to your code :

const format = require('@sturdynut/i18n-phone-formatter');

6. Build and Deploy

After writing your CCA, build the project by running the following command:

npm run build <nameOfTheFolder>

This command creates a dist/ folder inside your project, which contains the compiled code.

Unfortunately, there’s no automated deployment for the compiled code. You will need to manually copy and paste the contents of dist/index.js into the Custom Coded Action block in HubSpot.

Conclusion

HubSpot-OperationHub-cca-compiler is a valuable tool for anyone looking to overcome limitations in HubSpot’s Operations Hub. It empowers you to work with the libraries you need, providing greater flexibility in your custom coding projects. With an easy setup process and well-structured templates, this tool streamlines the development and deployment of Custom Coded Actions, enhancing your capabilities within HubSpot.