If you're using an e-commerce platform like BigCommerce integrated with HubSpot, you've probably noticed this frustrating quirk:
Orders are associated with Contacts, but not with their Companies — even when the Contact is properly linked to a Company.
This creates problems for reporting, automation, and visibility — especially in B2B environments where you need to know which company placed which order.
You can read the entire process in this blog post. Or you can watch the tutorial video that's embedded on the bottom of this page. Let's begin...
We used a custom-coded workflow action inside HubSpot to automatically associate a Contact’s primary Company with the corresponding Order whenever a new Order is created.
This required:
A HubSpot Private App to securely authenticate API calls
A custom workflow in HubSpot with a code action
A short JavaScript script that fetches associations and links the records
The best part? Once set up, it works completely in the background — no more manual associations.
Go to Settings > Integrations > Private Apps
Click “Create Private App”
Name it something like Order Association Tool
Under Scopes, check:
crm.objects.orders.read
crm.objects.orders.write
crm.objects.contacts.read
crm.objects.companies.read
Click Create App and copy the access token (you’ll need this once — keep it safe!)
Go to Automation > Workflows and create a new workflow based on the Order object
Set the enrollment trigger:Order is created (or further refine by only enrolling orders within a specific pipeline or based on other order properties)
Add an action:
“Custom Code”
Inside the code editor, click the “Secrets” tab
Click “Add Secret”
Key: HUBSPOT_PRIVATE_APP_TOKEN
Value: (paste your private app token here)
Here’s the script to paste into your code block:
Want ChatGPT to build something similar for your own use case? Try this prompt:
"I'm using HubSpot and have a custom object that needs to be automatically associated with another object based on an existing relationship. Can you write a custom-coded workflow action that pulls an associated record from one object and links it to another using the HubSpot API? Please include all necessary scopes and sample code."
This will get you 80% of the way there — and you can tweak from there.
If you're using BigCommerce or any eCommerce system connected to HubSpot, and your Orders aren’t being associated with Companies, this quick automation closes that gap — permanently.
You’ll gain:
Cleaner reporting
More reliable automation
Better sales & service insights
Need help implementing this? Or want to build more HubSpot workflow automations like this one?
Contact us at The Gist — we live for this stuff.