To create an integration workflow, I need to create a mapping table to map a HubSpot value to its value in the other system. Created the table no issue, but short of an API call (which to me is going out of HubSpot to come back in to talk to HubSpot) is there any way to access the table in Workflow Custom Code?
Hello @NCosgrove
there is a way to access the mapping table in Workflow Custom Code without making an API call to HubSpot.
You can store the mapping table as a JSON object in a HubSpot property and then access that property within the custom code. Here are the steps to do this:
Create a new text-based custom property in HubSpot to store the mapping table. This property should be added to the object where you will be running the workflow (e.g. contact, company, deal, etc.).
Give the property a name that you will recognize in your code (e.g. “mapping_table”).
Populate the mapping table as a JSON object in the value of the new custom property. You can do this manually in the property value field, or using the HubSpot API.
In the Workflow Custom Code action, use the HubSpot API to retrieve the value of the “mapping_table” custom property.
You can use the get function from the hubspot-api npm package to do this. Here’s an example:
const hubspot = require('@hubspot/api-client');
const { portalId, objectId } = inputData;
const propertyName = 'mapping_table';
const client = new hubspot.Client({ apiKey: process.env.HAPIKEY });
const objectApi = new hubspot.crm.ObjectsApi(client);
const getProperty = await objectApi.getProperty(portalId, objectId, propertyName);
const mappingTable = JSON.parse(getProperty.value);
This code retrieves the value of the “mapping_table” property for a specific object and parses it as a JSON object. You can then use this mapping table in your custom code as needed.
Note: Make sure to handle any errors that may occur when retrieving the custom property value, and to handle cases where the property value is empty or invalid.