Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
jackcoldrick90 / assignOwnerUsingZipOption1.js
Created April 26, 2022 22:06
There may be times where you'd like to assign ownership of a record using the likes of zip code/postal code. Often in situations like these there are hundreds if not thousands of values. The code snippets below show how you can solve for this using Operations Hub Professional.
/*
* This code snippet first gets a reference to the contacts postal code. Then it checks a series of arrays for the value. Each
* array represents a reps territory or region. When a match is found we assign the HubSpot Owner ID value to a variable and
* pass this back to the workflow using the callback object. You are then able to copy this value into the "HubSpot Owner"
* property.
/
exports.main = async (event, callback) => {
// Store contact postal code in variable
const zip = event.inputFields['zip'];
@jackcoldrick90
jackcoldrick90 / getDealAssociatedLineItemNames.js
Created April 26, 2022 08:27
Can be used to gain a reference to the associated line item names of a deal in HubSpot
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
let lineItemNames = [];
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
@jackcoldrick90
jackcoldrick90 / calculateUpsellValue.js
Created April 20, 2022 09:10
This code takes the most recently enrolled deal and using the associated company ID obtains the close amount of the most recently closed deal. It then passes this data back to the workflow which is copied toa property value and we can use this to calculate the upsell value.
/*
* Overview: This code takes the most recently enrolled deal and using the associated company ID obtains the close amount of the most recently closed deal.
* It then passes this data back to the workflow which is copied toa property value and we can use this to calculate the upsell value.
*/
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
let companyId, recentDealClosedAmount; // Variables will be used later
@jackcoldrick90
jackcoldrick90 / copyLineItemsToCompanyProperty.js
Last active April 19, 2022 23:00
This code looks at all line items associated with a deal. It then updates a multiple checkbox property for the associated company so we can store properties at a company level. * This allows us to quickly and easily view products when viewing a company record, segment companies for account based selling and use company workflows to set a "best n…
/*
* Overview: This code looks at all line items associated with a deal. It then updates a multiple checkbox property for the associated company so we can store properties at a company level.
* This allows us to quickly and easily view products when viewing a company record, segment companies for account based selling and use company workflows to set a "best next product".
* The "best next product" represents the most appropriate product to cross sell based on the current products associated with a company.
*/
//1. Import HubSpot Client Library.
const hubspot = require('@hubspot/api-client');
//2. Function houses our logic.
@jackcoldrick90
jackcoldrick90 / createContactfromConversationThread.js
Created April 8, 2022 14:07
Using the Conversations Inbox & Messaging API (https://developers.hubspot.com/docs/api/conversations/conversations) we can pull the body of an email, parse the content and create a contact in the CRM using the Contact API (https://developers.hubspot.com/docs/api/crm/contacts).
//1. Import required libraries
const hubspot = require('@hubspot/api-client');
const axios = require('axios');
exports.main = async (event, callback) => {
//2. Store threadID in variable, we'll use this to pull information
const threadID = event.inputFields['hs_thread_id'];
//3. Make a request to the conversations API to retrieve text - https://developers.hubspot.com/docs/api/conversations/conversations
/*
Example 1: Connect to a MySQL Database using NodeJS. Check to see if a record exists that matches the email address of the currently enrolled contact.
If they do exist, we do nothing. If they do not exist we add a record to the database.
*/
//1. Include the mysql node library
const mysql = require('mysql');
exports.main = async (event, callback) => {
/*
Operations Hub Workshop #3: Workflow 1 Code
This code is used to generate a random number that will be assigned to anyone who joins our referral program.
*/
//1. Import required libaries
const Promise = require("bluebird"); // Javascript Promise Library
const randomNumber = require("random-number-csprng"); // Javascript Random Number Generator
exports.main = (event, callback) => {
@jackcoldrick90
jackcoldrick90 / plus1referral.js
Created February 16, 2022 12:37
This code will create a contact off the back of a form submission whereby a user is prompted to provide details for a plus 1.
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const fname = event.inputFields['firstname'];
const lname = event.inputFields['lastname'];
const plus1FirstName = event.inputFields['plus_1_first_name'];
const plus1LastName = event.inputFields['plus_1_last_name'];
const plus1EmailAddress = event.inputFields['plus_1_email_address'];
@jackcoldrick90
jackcoldrick90 / operations_hub_workshop_2_example_1.js
Created February 10, 2022 10:41
OPERATIONS HUB WORKSHOP #2: Email Validation using Kickbox - Collection of code snippets from the first workshop.
/* Example 1: Make a HTTP Request to Kickbox Verification API using NodeJS request. */
//1. Import libraries, in this instance "request" to make HTTP requests
const request = require('request')
exports.main = async (event, callback) => {
//2. Define variables to store data
var role, free, disposable, sendex, result, reason; // We will use these later on when data is returned from Kickbox
const email = event.inputFields['email']; // We store the contact email in a variable and will query Kickbox
@jackcoldrick90
jackcoldrick90 / operations_hub_workshop_1_example_1.js
Last active March 15, 2023 19:02
OPERATIONS HUB WORKSHOP #1: Data Enrichment using Clearbit - Collection of code snippets from the first workshop.
const request = require('request');
exports.main = async (event, callback) => {
//1. Store the company domain in a variable
var companyDomain = event.inputFields['domain'];
var domainAlias, tech, subIndustry, legalName;
//2. Configure request to Clearbit Discovery API
var options = {