Skip to content

How to Automatically Associate Orders with Companies in HubSpot

|

June 17, 2025

SHARE THIS ARTICLE

Get insights in your inbox.

Schedule an exploratory call. 
Let’s Talk
How to Automatically Associate Orders with Companies in HubSpot - The Gist - Certified HubSpot Solutions Partner

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...

The Solution

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.

Step-by-Step Instructions

1. Create a Private App in HubSpot

  1. Go to Settings > Integrations > Private Apps

  2. Click “Create Private App”

  3. Name it something like Order Association Tool

  4. Under Scopes, check:

    • crm.objects.orders.read

    • crm.objects.orders.write

    • crm.objects.contacts.read

    • crm.objects.companies.read

  5. Click Create App and copy the access token (you’ll need this once — keep it safe!)


2. Create a Custom Workflow in HubSpot

  1. Go to Automation > Workflows and create a new workflow based on the Order object

  2. Set the enrollment trigger:
    Order is created (or further refine by only enrolling orders within a specific pipeline or based on other order properties)

  3. Add an action:
    “Custom Code”


3. Add the Access Token as a Secret

  1. Inside the code editor, click the “Secrets” tab

  2. Click “Add Secret”

    • Key: HUBSPOT_PRIVATE_APP_TOKEN

    • Value: (paste your private app token here)


4. Paste the Code

Here’s the script to paste into your code block:

Expand to See Code Block

 

 

Copy + Paste ChatGPT Prompt

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.


Here's the Gist

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.