Hubspot
Last updated
Last updated
Hubspot is a popular marketing automation software tool. In early 2022, Hubspot added Custom Code functionality to their Workflows, enabling a direct connection to Lob. Hubspot’s Workflows can be used to automatically trigger a mailpiece to be sent, via Lob.
(Looking for a no-code integration option? See here.)
A developer plan for testing with Lob is free, but you will need to create a Lob account to get your API Keys.
If you do not already have one, create a Hubspot account here. You’ll want to enable Operations Hub / Marketing Hub Professional trial (note this lasts 14 days): Automation > Workflows > Start 14 Day Trial
You can create manually, or import from a CSV by clicking Contacts > Import. From there, walk through the flow to import a file from your computer: Start an Import > File From Computer > One File > One Object > Contacts. Ensure your contacts have address parameters; you can use this CSV as an example.
We will be creating a list in the next step, so for this walkthrough, do not select “Create a List from this Import”.
In the Map File screen, for ‘Address2’, select ‘Create A New Property’, and name it ‘Address2’.
Contacts > Lists > Create List > Select ‘Static’ List > Contact-based > Name your List
Select Automation > Workflows
Click Create Workflow
Click Contact Based > Blank Workflow
For example, List Memberships > Select List you previously created > Is Member of List
Click + button on Workflow, beneath the Trigger
Select Custom Code
Here you can select Python or NodeJS. For this example, we will select Language: Python. Then we will map Lob’s API fields to Hubspot properties, and enter our custom code. For this example, Map Properties To Include in Code as follows:
Finally, enter your Python code, with properties defined as per the prior step. See example code below to test with.
If copying and pasting the Python code above, it is advised to run it through a Python code validator to ensure that no formatting issues occur as a result.
Next we need API credentials from our Lob account. Retrieve these credentials from your Lob dashboard by clicking on the Settings menu on the sidebar, then clicking on the API Keys tab.
In the example Python code, replace YOUR_API_KEY
with your Test API Key.
ENSURE YOU ARE USING YOUR TEST API KEY
You should also replace the front and back "HUBSPOT_CREATIVE
" with your own HTML, template IDs, or links to hosted static creatives. For example:
You can then log into your Lob account to verify that a mailpiece was generated.
Once you’ve tested, you can Publish your workflow. From there, it will run whenever the trigger you set is fired. For example, if you followed the above example, you can now add some contacts to your list. This should automatically create mailpieces for each person on the list.
Now you can replace the Test API key in your Python code with your Base64 Encoded Live API Key, and your Automation is live. If you are using other test resources like address IDs or template IDs, those will also need to be transferred to your live environment.
Make sure to hit ‘Save’. Then you can open your custom code back up, scroll to the bottom of the panel, and click Test Action. Select a contact, and click Test to fire off a test request.