Skip to content

Instantly share code, notes, and snippets.

/* Example 2: Make a HTTP Request to Kickbox Email Verification API using NodeJS axios */
//1. Import libraries, in this instance "axios" to make HTTP requests
const axios = require('axios');
exports.main = async (event, callback) => {
//2. Store contact email in variable
var email = event.inputFields['email'];
//3. Configure and Make our HTTP request to Kickbox Email Verification API
@jackcoldrick90
jackcoldrick90 / associateContactToCustomObject.js
Created November 21, 2023 16:50
Associates a contact to a custom object. Using Axios library for HTTP requests.
const axios = require('axios');
axios.defaults.headers.common['authorization'] = `Bearer ${process.env.HUBSPOTTOKEN}`;
axios.defaults.headers.common['Content-Type'] = `application/json`;
axios.defaults.headers.put['Content-Type'] = `application/json`;
exports.main = async (event) => {
const partner_id = event.inputFields['partner_id'];
const partnerObjectId = await getPartner(partner_id);
{
"results": [
{
"objectId": 245,
"title": "Example Title",
"link": "https://developers.hubspot.com/docs/api/crm/extensions/custom-cards",
"stringExample": "CRM Cards are really cool",
"statusExample": "Success",
"numberExample": 55.95,
"linkExample": "https://developers.hubspot.com",
@jackcoldrick90
jackcoldrick90 / getFileUploadandMakePublic.js
Created August 18, 2023 17:41
Use this action inside of a contact workflow. It can be used to make a file uploaded via form submission publicly accessible (but not indexable).
const axios = require('axios'); // Used for HTTP requests
axios.defaults.headers.common['Authorization'] = `Bearer ${process.env.HUBSPOTTOKEN}`; // Include access token in all request from Axios
// Retrieve the file redirect URL from form submission
function getRedirectUrl(attachment) {
let requestUrl = attachment;
return new Promise((resolve) => {
axios.get(requestUrl).then(res => {
resolve(getSubstring(res.request.res.responseUrl, 'form-uploads', '?'));
}).catch(err => { console.log(err.message) })
@jackcoldrick90
jackcoldrick90 / associateCustomObjectToContact.js
Created August 10, 2023 21:59
Code will associate a custom object to the contact associated to a deal.
// Import HubSpot Client Library and instantiate client with private app token
const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({
accessToken: process.env.HUBSPOTTOKEN // Access token associated with your private app (also be sure to include token in secrets)
});
// Helper function to get the associated Object ID of a specified Object Type
async function getAssociatedObjectId(objectType, objectId, toObjectType) {
let obj = await hubspotClient.crm.objects.associationsApi.getAll(objectType, objectId, toObjectType);
return obj.results[0].id;
@jackcoldrick90
jackcoldrick90 / send-transactional-email.py
Created August 7, 2023 22:51
Transactional Email #2 - SMTP API
import requests
import urllib
import json
import smtplib
import os
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
@jackcoldrick90
jackcoldrick90 / associateCompanyToContact.js
Created July 26, 2023 12:32
Script below can be used in a HubSpot Contact Workflow to associate a contact to a company using the value stored in the "company name" property. If the company exists it is associated. If the company does not exist, it is created and associated. Requires authentication with a private app.
// Import the Hubspot NodeJS Client Library - this will allow us to use the HubSpot APIs
const hubspot = require('@hubspot/api-client');
//Instantiate a new HubSpot API client using an access token (private app)
const hubspotClient = new hubspot.Client({
accessToken: process.env.HUBSPOTTOKEN
});
// Helper function to associate Company to Contact using HubSpot Client
function associateCompanyToContact(companyId, contactId) {
@jackcoldrick90
jackcoldrick90 / workflow-1
Created July 25, 2023 15:19
Code snippets to be used in two separate Hubspot workflows to create a referral program. The first will generate a random number (referral ID) the second will be used to attribute referrals back to the referring contact.
//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) => {
//2. Using a Promise, we first try to generate a random number
Promise.try(function() {
return randomNumber(10000, 50000); // Generate Random Number between a defined range
}).then(function(number) { // When the number is successfully generated we do this
@jackcoldrick90
jackcoldrick90 / Capture Country in state
Created July 25, 2023 09:09
Snippets below can be used to create a custom coded bot in Hubspot that communicates with the TicketMaster Discovery API: https://developer.ticketmaster.com/products-and-docs/apis/getting-started/
exports.main = (event, callback) => {
var countryCode;
var country;
switch(event.userMessage.quickReply.quickReplies[0].value) {
case "Ireland":
countryCode = "IE"
country = "Ireland"
@jackcoldrick90
jackcoldrick90 / queryHubDB.js
Created May 5, 2022 13:25
This snippet queries a HubDB table. The table in this instance contains various product related resources. You can use the information returned to copy into properties on the contact record and personalise an email or segment via list for smart content
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const product_of_interest = event.inputFields['product_of_interest'];
let resourceName, resourceLink, resourceDescription, resourceImage;
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});