Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
let Existing = inputData.existing_values;
let Existing_Labels = inputData.existing_labels;
let Looped_Output = "";
Existing = Existing.split(",");
Existing_Labels = Existing_Labels.split(",");
for (let i = 0; i < Existing.length; i++) {
Looped_Output += '{\n "label": "' + Existing_Labels[i] +'", \n"value": "' + Existing[i] + '"\n},\n';
}
@HubSpotHanevold
HubSpotHanevold / Using fetch to retrieve whole json body in Zapier.js
Created December 8, 2022 15:27
Retrieving an email template from HubSpot to do a find and replace on the full body.
let cloneId = inputData.cloneId;
let token = inputData.token;
let auth = 'Bearer ' + token;
fetch('https://api.hubapi.com/marketing-emails/v1/emails/'+ cloneId , {
headers: {authorization: auth}
})
.then(function(res) {
return res.text();
})
@HubSpotHanevold
HubSpotHanevold / appending dropdown multi-picklist when value does not exist.php
Last active January 12, 2023 16:51
A php webhook endpoint that will append a multi-picklist with missing values. Also, returns the property update values in an easy way to use in a custom code action later in the workflow.
<?php
// RETRIEVE THE CURRENT DROPDOWN VALUES FOR THE LINE-ITEM PROPERTY
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.hubapi.com/crm/v3/properties/deal/line_items',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
@HubSpotHanevold
HubSpotHanevold / auto increment a deal record using crm search api.js
Last active January 17, 2023 18:28
This custom coded action takes the most recent value from the record type in question then adds a value to that previous amount. Use this code for auto incrementing records.
var axios = require('axios');
const auth = 'Bearer ' + process.env.ADD_YOUR_SECRET_KEY_NAME_HERE;
exports.main = async (event, callback) => {
var data = JSON.stringify({
"filterGroups":[
{
"filters":[
{
@HubSpotHanevold
HubSpotHanevold / omit blog ids with hubl.js
Created January 30, 2023 16:36
A way to omit certain blogs from filtered lists via HubL array
{% set used_ids = [1, 2, 3, 5, 6] %}
{% set new_ids = [1, 2, 4, 5, 7, 8] %}
{% set ids_to_use = new_ids|difference(used_ids) %}
{% for id in ids_to_use %}
{{id}}
{% endfor %}
exports.main = async (event, callback) => {
const old_plan_amount = event.inputFields['old_plan_amount'];
const new_plan_amount = event.inputFields['new_plan_amount'];
if(old_plan_amount == new_plan_amount) {
callback({
outputFields: {
delta: 'none'
}
{# NOTE THESE CAN ALL BE ADJUSTED TO USE PLACEHOLDER VALUES INSTEAD OF DEFINED IN THE CODE #}
{# START AND END TIMES FOR THE EVENT #}
{% set google_start_time = "T230000Z" %}
{% set google_end_time = "T240000Z" %}
{% set outlook_start_time = "T23:00:00+00:00"|urlencode %}
{% set outlook_end_time = "T24:00:00+00:00"|urlencode %}
{# STATIC VALUES - DEFINED #}
{% set event_title = "Sample webinar title"|urlencode %}
const axios = require('axios');
exports.main = async (event, callback) => {
try {
// Replace with secret name
const auth = process.env.SAMPLESECRETNAME;
// Replace variables below as needed
const hsObjectId = event.inputFields['hs_object_id'];
const cpa = event.inputFields['cpa____'];
@HubSpotHanevold
HubSpotHanevold / gist:4389bf7555a0cb33074588e84ba4b17c
Last active May 16, 2024 20:03
Abandoned Cart Email Module Example
<!-- REMEMBER 'USE MODULE FOR PROGRAMMABLE EMAIL' MUST BE SELECTED -->
<!-- RETRIEVE PAYLOAD DATA FROM CONTACT RECORD -->
{% set cart_items = contact.abandoned_cart_json_payload | fromjson %}
<!-- HEADER ROW -->
<table style="width: 100%; border-collapse: collapse;">
<tr>
<th style="width: 20%; text-align: left; font-weight: bold; border: none;"></th>
<th style="width: 60%; text-align: left; font-weight: bold; border: none;"></th>
<th style="width: 10%; text-align: right; font-weight: bold; border: none;">Qty</th>
const axios = require('axios');
const crypto = require('crypto');
exports.main = async ({ body }, sendResponse) => {
if(body.event == 'endpoint.url_validation'){
try {
sendResponse({ body: {encryptedToken: crypto.createHmac('sha256', 'TOKEN ADDED HERE').update(body.payload.plainToken).digest('hex'), plainToken: body.payload.plainToken}, statusCode: 200 });
} catch(e){
sendResponse({ body: e, statusCode: 200 });
}