I'm new to Hubspot custom code option in workflow. I have some code in workflow custom code. Please help me what is this code related to.
//1. Import required libraries const hubspot = require('@hubspot/api-client'); // HubSpot Node Client will allow us to make calls to HubSpot API
exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({"accessToken":"pat-na1-XXXXXXXXXXXXXXXX"});
//2. Get email address of Contact (Prospect in Salesforce) Owner assigned by SF in a variable var sfOwnerEmail = event.inputFields['sf_owner_email']; const sfOwnerName = event.inputFields['prospect_owner__sf_'];
//7. Updating the Contact that triggered the workflow, with OwnerId to assign owner. const apiResponse = await hubspotClient.crm.contacts.basicApi.update(event.object.objectId, { "properties": { "hubspot_owner_id": ownerId } })
Hi, @DSaini1👋 Thanks for your post. Out of curiosity, is this code that you inherited?
Here's a high-level view of what this code is set up to do:
The code starts by importing the required libraries to make API calls to HubSpot from Node.js
The script retrieves the email address of a Salesforce contact owner and sets it to a variable. It also retrieves the Salesforce name of the contact owner and sets it to another variable
The code checks if the Salesforce contact owner name is equal to either “abc” or “xyz”, and if it is, it sets the email address in the previous variable to a specific test email address
The script sends an API request to HubSpot to retrieve information about the user associated with the email address in the variable. Specifically, it retrieves the owner ID property and email property of the user
The code updates the contact record for the contact that triggered the workflow with the retrieved owner ID property as the value for the “hubspot_owner_id” property of the contact record.
I hope this helps get you moving forward.
Have fun building! — Jaycee
Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.