Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
@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 / 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 / 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();
})
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 / zip_code_formatter.js
Created November 16, 2022 17:24
Formatting zip code to remove characters, spaces and trim to 5 digits
exports.main = async (event, callback) => {
const zip = event.inputFields['zip'];
// REMOVE ANY EMPTY SPACES FROM THE ZIP CODE
let no_spaces_zip = zip.replace(/\s/g, '');
// REMOVE ANY NON-NUMERICAL CHARACTERS
let no_character_zip = no_spaces_zip.replace(/\D/g,'');
// MEASURE THE LENGTH OF THE ZIP CODE
let zip_length = no_character_zip.length;
// IF THE ZIP CODE IS 5 CHARACTERS
@HubSpotHanevold
HubSpotHanevold / meeting_cancel_reschedule_links.js
Created November 9, 2022 22:14
A way to retrieve the cancel or reschedule links from a meeting body
exports.main = async (event, callback) => {
const firstname = event.inputFields['firstname'];
const lastname = event.inputFields['lastname'];
let fullname = firstname + ' ' + lastname;
callback({
outputFields: {
fullname: fullname
}
});
}
const request = require('request');
exports.main = async (event, callback) => {
const email = event.inputFields['email'];
let domain = email.split('@')[1];
let username = email.split('@')[0];
var options = {
'method': 'GET',
const request = require('request');
exports.main = async (event, callback) => {
const REPLACE = event.inputFields['REPLACE'];
var options = {
'method': 'GET',
'url': 'https://api.hubapi.com/hubdb/api/v2/tables/REPLACE/rows?',
'headers': {
@HubSpotHanevold
HubSpotHanevold / custom_coded_action_search_crm_custom_object.js
Created September 15, 2022 23:10
search crm for custom object for custom coded actions
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
// Instantiate a new HubSpot API client using the HAPI key (secret)
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
// Create search criteria