Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
jackcoldrick90 / validateEmailFromKickbox.js
Created April 26, 2021 17:08
Action uses the Kickbox Single Verification API to validate the enrolled contacts email address and return additional information to help optimize your marketing email efforts. i.e Sendex score.
//Import required libraries
const hubspot = require('@hubspot/api-client');
const request = require('request');
exports.main = (event, callback) => {
//Create a new HubSpot Client
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
@jackcoldrick90
jackcoldrick90 / enrichCompanyDataFromClearbit.js
Created April 26, 2021 17:12
This custom coded action queries the ClearBit Company API - domain lookup endpoint to pull additional information relating to the currently enrolled company. When a response is returned we then use the HubSpot CRM Company API to update the properties with the appropriate values.
// Import required libraries
const hubspot = require('@hubspot/api-client');
const request = require('request');
exports.main = (event, callback) => {
// Create a new HubSpot API client
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
@jackcoldrick90
jackcoldrick90 / updateReferringContactHubspot.js
Created April 26, 2021 17:17
When a deal is created and the Referrer ID is known trigger a custom coded workflow action that will: Use the CRM Search API to Search for the contact with the matching Referrer ID. The CRM API to update the Contacts total number of referrals & Recent Referral Date properties.
// Import the required libraries - in this instance the HubSpot NodeJS API client
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
// Create a new instance of the HubSpot client
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
@jackcoldrick90
jackcoldrick90 / splitFullName.js
Last active May 10, 2022 19:28
Using Hubspot Operations Hub Custom Coded workflow action you can split the full name provided by a contact and store in the firstname and lastname properties. Ideal if you're asking for the entire name in a single field on the form.
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["full_name"])
.then(results => {
@jackcoldrick90
jackcoldrick90 / referralProgramGenerateUniqueCode.js
Last active April 30, 2023 07:09
This snippet generates a unique code using Math.random(). This code can be used in a referral program
// Import the required libraries - HubSpot NodeJS API client
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
// Secrets can be accessed via environment variables.
// Make sure to add your API key under "Secrets" above.
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
@jackcoldrick90
jackcoldrick90 / referralProgramAttribution-v2.js
Last active September 12, 2023 20:27
This script looks at the "referrer" property associated with the contact that has just converted and then leverages the CRM Search APi to find the matching contact with that specific "referrer ID". It then uses the CRM API to update the contacts "recent referral date" and "total referral" properties.
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
//1) Get the enrolled deal - referrer_id property value
hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["referrer"])
@jackcoldrick90
jackcoldrick90 / addDateSuffix.js
Last active March 8, 2022 12:50
This script is designed to be used within a custom coded workflow action (Operations Hub Professional) and adds the appropriate suffix depending on the day of the month. It relies on you already having the date stored in a single line text property DD/MM/YYYY. Worth noting this assumes you are storing the date in DD/MM/YYYY format. If you are us…
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["selected_date"])
.then(results => {
@jackcoldrick90
jackcoldrick90 / searchMySQLDB.js
Created May 19, 2021 12:13
This is an example of a code snippet that checks to see if a contact exists in an external DB (MySQL). If it does we update a property to "true" otherwise "false".
// Import required libraries
const hubspot = require('@hubspot/api-client');
const mysql = require('mysql');
// This function is called when the custom coded action is executed
exports.main = (event, callback) => {
// Create a new instance of the HubSpot API Client - we need this to interact with the CRM APIs to retrieve information relating to the currently enrolled record
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
@jackcoldrick90
jackcoldrick90 / associateContactToCompany.js
Last active March 27, 2024 08:28
This custom code snippet can be used to associate a contact to a company based on the company name property that is stored at a contact level. It's particularly useful if your customers are using a freemail address and aren't supplying a company website - just the name of their company. If no company is found a new record will be created in the …
// Import the Hubspot NodeJS Client Library - this will allow us to use the HubSpot APIs
const hubspot = require('@hubspot/api-client');
/*
This function is called when the custom code action is executed. It takes 2 arguements. The first is the event object which contains information on the currently enrolled object.
The second is the callback function which is used to pass data back to the workflow.
*/
exports.main = (event, callback) => {
// Instantiate a new HubSpot API client using the HAPI key (secret)
@jackcoldrick90
jackcoldrick90 / createTrelloBoardListAndCard.js
Created June 9, 2021 08:36
Using Trello Rest API we can update boards/lists/cards when data changes within the HubSpot CRM. In the below example we create a new board, create a list within that board and add a test card to that board. https://developer.atlassian.com/cloud/trello/rest/api-group-actions/
const hubspot = require('@hubspot/api-client');
const request = require('request');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, ["dealname"])