Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
exports.main = async (event, callback) => {
/*****
Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
*****/
const callNote = event.inputFields['hs_call_body'];
// Step 1: Split the string into key-value pairs
const keyValuePairs = callNote.split(';');
// Step 2: Store values in variables
exports.main = async (event, callback) => {
let state_zips = [
{ "state": "AL", "zip_low": 35004, "zip_high": 36925 },
{ "state": "AK", "zip_low": 99501, "zip_high": 99950 },
{ "state": "AZ", "zip_low": 85001, "zip_high": 86556 },
{ "state": "AR", "zip_low": 71601, "zip_high": 72959 },
{ "state": "CA", "zip_low": 90001, "zip_high": 96162 },
{ "state": "CO", "zip_low": 80001, "zip_high": 81658 },
{ "state": "CT", "zip_low": 6001, "zip_high": 6928 },
{ "state": "DE", "zip_low": 19701, "zip_high": 19980 },
@HubSpotHanevold
HubSpotHanevold / sample.php
Created April 16, 2025 16:33
Sample PHP Curl Forms Submit API
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.hsforms.com/submissions/v3/integration/submit/portalId/formGuid',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
@HubSpotHanevold
HubSpotHanevold / script.js
Last active December 3, 2024 20:00
Validate additional property as email only
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
const emailInput = document.querySelector('input[name="2-8330456/tour_contact_email"]');
emailInput.addEventListener("input", function() {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const parentDiv = emailInput.closest('.input');
let messageDiv = parentDiv.querySelector('.email-error');
@HubSpotHanevold
HubSpotHanevold / script.php
Last active December 3, 2024 16:36
A php script to replicate HubSpot properties created on a standard object and add to a custom object. Only creates non-HubSpot default properties on the new object.
<?php
// PHP SCRIPT TO MOVE PROPERTIES FROM A STANDARD OBJECT TO A CUSOTM OBJECT
// READ ME
// MODIFY THESE VARIABLES BELOW AS YOU SEE FIT (LINES 8-10)
// ALSO MODIFY THE GROUP NAME MAPPINGS BELOW (LINES 53-56)
$authToken = 'ADD_YOUR_TOKEN_HERE';
$standardObject = 'contacts';
$customObjectInternalName = '2-37668321';
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 13, 2024 16:47
Push URL of page to a form property
<script>
document.addEventListener("DOMContentLoaded", function() {
// Wait for the form to load
setTimeout(function() {
var urlInput = document.querySelector('input[name="url_of_page"]');
if (urlInput) {
console.log('url_of_page input exists');
urlInput.value = window.location.href;
}
},1000); // Adjust the delay if needed
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 17:15
Melissa Data Integration
<script>
window.onload = function () {
// Function to poll for the existence of the input field
function waitForElement(selector, callback) {
const inputField = document.getElementsByName(selector)[0];
if (inputField) {
callback(inputField);
} else {
setTimeout(function () {
waitForElement(selector, callback);
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 00:46
Using typeahead on a HubSpot form
// include the following scripts that can be found here https://select2.org/getting-started/installation
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
// in the below, we listen for the form to load, then switch out the standard select element (by name) with a select2 element
<script>
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
// Initialize Select2 on the specified select element - update with the internal name of the property where it says internal_select_name
const selectElement = $('select[name=internal_select_name]').select2();
import requests
url = "api.hubspot.com/events/v3/events/?objectType=contact&objectId=52054635672"
payload = ""
headers = {
'Authorization': '••••••'
}
response = requests.request("GET", url, headers=headers, data=payload)
exports.main = async (event, callback) => {
var phone = event.inputFields['phone'];
console.log("Input Phone: ", phone)
const outputFields = {
valid: false,
validation_message: "",
phone: ""
}