HubSpot Workflows make it easy to automate personalized emails based on customer data. But here's the gap: HubSpot doesn't natively support automating direct mail. That means direct maila channel that often outperforms email on response ratesis still stuck in manual mode while email, SMS, and ads run on autopilot.
Lob's Direct Mail APIs change that. By connecting Lob to your HubSpot Workflows, you can trigger personalized postcards the same way you trigger emails automatically, based on list membership, lifecycle stage, or any other contact property. No manual sends. No batch-and-blast. Just direct mail that runs when your workflow says go.
Below is a step-by-step guide on how to use Lob API integrations to add direct mail into your HubSpot Workflows and automatically send a postcard. The whole setup takes about 30 minutes and once it's live, every new contact added to your list triggers a personalized mailpiece automatically.
Steps to connect your HubSpot Workflows to Lob
Create your Lob and HubSpot accounts
Before you start, you'll need two accounts:
- Lob: Create a Lob account to get your API Keys. A developer plan for testing is free.
- HubSpot: If you don't have one, create a HubSpot account here. You'll need Operations Hub or Marketing Hub Professional enabled. If you don't have access, you can start a free 14-day trial: Automation > Workflows > Start 14 Day Trial
Import your contacts
In HubSpot, you can create contacts manually or import from a CSV. To import, click Contacts > Import and follow this path:
Start an Import > File From Computer > One File > One Object > Contacts
Make sure your contacts include address fields street, city, state, and ZIP. Without those, Lob can't generate a mailpiece. You can use this CSV as an example.
Note that 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'.

Create a list
Contacts> Lists> Create List> Select 'Static' List> Contact-based> Name your List

Create a workflow
Select Automation> Workflows

Click Create Workflow

Click Contact-based> Blank workflow

Set up your enrollment trigger
In this example, we'll set up the trigger so that adding a contact to your list automatically fires off a postcard. Here's the path:
List Memberships > Select the List you previously created > is member of list



Add an action to your workflow
Beneath Contact enrollment trigger, click +

Under Workflow, select Custom Code

For Language, select Python (you can also use NodeJS, but this walkthrough uses Python).
Next, map Lob's API fields to your HubSpot contact properties. Under Property to Include in Code, add the following:

Finally, enter your Python code, with properties defined as per the prior step. See example code (below the screenshot) to test with.
(To learn more about Lob's codeexplore the API docs here.)

Sample Python Code:import requests import json import base64 import os from hubspot import HubSpot from hubspot.crm.contacts import ApiException from requests.adapters import HTTPAdapter from urllib3.util.retry import Retry
def retry_session(retries, session=None, backoff_factor=1): session = session or requests.Session() retry = Retry( total=retries, read=retries, connect=retries, backoff_factor=backoff_factor, status_forcelist=[500, 502, 503, 504, 429], allowed_methods=['POST'] ) adapter = HTTPAdapter(max_retries=retry) session.mount('http://', adapter) session.mount('https://', adapter) return session
def main(event):
address = event.get('inputFields').get('address') city = event.get('inputFields').get('city') state = event.get('inputFields').get('state') zip_code = event.get('inputFields').get('zip_code') email = event.get('inputFields').get('email') hs_object_id = event.get('inputFields').get('hs_object_id') phone = event.get('inputFields').get('phone') firstname = event.get('inputFields').get('firstname') lastname = event.get('inputFields').get('lastname')
url = "https://api.lob.com/v1/postcards"
payload = json.dumps({ "description": "HUBSPOT DEMO POSTCARD", "to": { "name": firstname + ' ' + lastname, "address_line1": address, "address_line2": address_line2, "address_city": city, "address_state": state, "address_zip": zip_code }, "front": "HUBSPOT_CREATIVE", "back": "HUBSPOT_CREATIVE", "size": "4x6", "metadata": { "customer_id": hs_object_id, "campaign": "HUBSPOT_TEST", "phone": phone, "email": email, "front": "demo_hubspot_front_creative", "back": "demo_hubspot_back_creative", "address_city": city, "address_state": state, "address_zip": zip_code } })
headers = { 'Authorization': 'Basic [BASE64-ENCODED API_KEY:]', 'Content-Type': 'application/json' }
session = retry_session(retries=5) r = session.post(url, headers=headers, data=payload) j = r.json() print(j)
Add your API keys
Next, you need API credentials from your Lob account. Retrieve them from your Lob dashboard: Settings > API Keys.
Use your Test API Key for this step not your Live key. Live keys will trigger real mail sends and real charges.
To encode your key for the Python script:
- Copy your Test API Key (e.g.,
test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc) - Append a colon to the end:
test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: - Paste it into a Base64 Encoder tool
- Copy the encoded result (e.g.,
dGVzdF8wZGM4ZDUxZTBhY2ZmY2IxODgwZTBmMTljNzliMmY1YjBjYzo=)
Replace [BASE64-ENCODED API_KEY:] in your Python script so the Authorization header reads: 'Authorization': 'Basic dGVzdF8wZGM4ZDUxZTBhY2ZmY2IxODgwZTBmMTljNzliMmY1YjBjYzo='
Add your postcard creative
You should also replace the front and back "HUBSPOT_CREATIVE" with your own HTML, template IDs, or links to hosted static creatives. For example,
"front": "https://s3.us-west-2.amazonaws.com/public.lob.com/solutions/retail_pdfs/4x6+Retail+front.pdf",
"back": "https://s3.us-west-2.amazonaws.com/public.lob.com/solutions/retail_pdfs/4x6+Retail+back.pdf",
(For more about designing/formatting creative for Lob, go here.)
Make sure to hit 'Save'.
Test your workflow
Then you can re-open your custom code, scroll to the bottom of the panel, and click Test Action. Select a contact, and click Test to fire off a test request.

You can then log into your Lob account to verify that your postcard was generated; you should see it your dashboard under Postcards (Test). The below is the result of the example creative.

Publish and run your workflow
Once you've tested successfully, click Publish to activate your workflow. From here, every contact added to your list will automatically trigger a postcard no manual sends needed.
When you're ready to send real mail, swap your Test API Key for your Base64-encoded Live API Key in the Python code. You'll also need to add payment information to your Lob account before live mailpieces will print and ship.
And this is just the starting point. Once the HubSpot-to-Lob connection is live, you can build direct mail workflows around lifecycle stage changes, deal closures, renewal dates, or any other HubSpot trigger so direct mail runs as automatically as your email sequences.
Wrap up
Your direct mail channel now runs on the same trigger logic as your email workflows. Your team spends less time on repetitive sends, your contacts receive mail timed to their actions, and you can track every mailpiece from creation through delivery inside your Lob dashboard.
To dig deeper into what's possible, explore the Lob API docs or check out our full integration guides.
Frequently Asked Questions
FAQs
Does HubSpot natively support direct mail automation?
Nothat's why you need Lob's API to add direct mail to your workflows.
Is direct mail part of a CRM strategy?
Yesand for many teams, it's essential. When you connect direct mail to HubSpot, you can trigger physical mail based on real customer actions: a new lead added to a list, a renewal window opening, a lapsed customer worth re-engaging.
What do I need before connecting Lob to HubSpot Workflows?
A Lob account, a HubSpot account with Operations Hub or Marketing Hub Professional, and contacts with valid address fields. The setup section above covers the details.
How do I switch from test sends to live direct mail?
See the "Publish and run your workflow" section above for full details on switching from Test to Live API keys and adding payment information.
.avif)

.png)




