Reference

How data actually moves between HubSpot and MYOB

Eight sections covering the full system: how the two platforms get connected, how syncs get triggered and isolated from each other, what happens on each side for products, customers, and invoices, exactly which properties move where, and the origin-tracking logic that decides whether a deleted record should be recreated or left alone.

Architecture

System overview

The HubSpot settings page never talks to MYOB or to HubSpot's own CRM API directly — every request goes through the backend, which is the only thing holding OAuth credentials for either side.

flowchart LR
  classDef ext fill:#F3D9C9,stroke:#C85A35,color:#5A2E15
  classDef backend fill:#DDEAFB,stroke:#3D6FA6,color:#122A45
  classDef store fill:#E7E2F5,stroke:#7C5CBF,color:#2E1F4D

  UI["Settings UI Extension
(iframe inside HubSpot)"]:::ext API["Backend API
Express on ECS Fargate"]:::backend DB[("Postgres
connections · sync jobs · sync records")]:::store Q{{"Redis + BullMQ
scheduled job queue"}}:::store HSAPI["HubSpot CRM API"]:::ext MYOBAPI["MYOB AccountRight API"]:::ext STRIPE["Stripe Billing"]:::ext UI -- "hubspot.fetch()
HMAC-signed" --> API API -- "portal OAuth token" --> HSAPI API -- "per-portal OAuth token" --> MYOBAPI API -- "read / write" --> DB API -- "enqueue + consume" --> Q API -- "checkout + webhooks" --> STRIPE
Notice
  • The iframe is a thin client — it holds no credentials of its own. Every call is signed with an HMAC checked by requireHubSpotSignature middleware.
  • Postgres carries three kinds of state that matter for the rest of this map: the OAuth connections, the SyncJob queue/history, and MyobSyncRecord — the table that remembers which HubSpot record maps to which MYOB record, and which side created it first.
Auth

Connecting the two systems

Two entirely independent OAuth flows. Installing the HubSpot app does not connect MYOB, and connecting MYOB happens per HubSpot portal, carrying the portal ID through as signed OAuth state.

sequenceDiagram
  participant Admin
  participant HubSpot
  participant Backend
  participant MYOB

  Admin->>HubSpot: Install app
  HubSpot->>Backend: GET /auth/hubspot/callback?code
  Backend->>HubSpot: exchange code for tokens
  Backend->>Backend: saveInstall()
+ auto-install MYOB properties Backend-->>Admin: "HubSpot app connected" Admin->>Backend: GET /auth/myob/start
?hubspotPortalId&companyFileUsername Backend-->>Admin: redirect to MYOB consent
(state = signed portalId + username) Admin->>MYOB: approve access MYOB->>Backend: GET /auth/myob/callback
?code&businessId&state Backend->>MYOB: exchange code for tokens Backend->>Backend: saveMyobConnection()
keyed by portalId Backend-->>Admin: redirect back to HubSpot settings
Notice
  • MYOB rotates the refresh token on every use. A long sync can outlive one access token, so refresh happens per API call, not once per sync — and the refreshed token is shared across any other sync running concurrently for the same portal.
  • Installing the HubSpot app also fires a one-time property setup (ensureHubSpotMyobProperties) so the MYOB-related custom properties exist before anyone tries to use them.
Orchestration

Scheduling & job lifecycle

Manual clicks and BullMQ's cron scheduler both end up calling the exact same per-portal sync function — the only difference is what triggers it.

flowchart TD
  classDef trigger fill:#F3D9C9,stroke:#C85A35,color:#5A2E15
  classDef job fill:#DDEAFB,stroke:#3D6FA6,color:#122A45
  classDef guard fill:#FBEFD1,stroke:#C99A3D,color:#5A4212

  M["Manual click
(Settings / Manual Sync page)"]:::trigger S["BullMQ JobScheduler
cron, per portal + object type"]:::trigger M --> START["start<X>SyncJob(portalId)"] S --> WORKER["Worker picks up job
{portalId, objectType, direction}"] WORKER --> START START --> GUARD{"findActiveSyncJob:
already queued or running?"}:::guard GUARD -- yes --> REUSE["Return the existing job —
no duplicate run"] GUARD -- no --> QUEUED["SyncJob: queued"]:::job QUEUED --> RUNNING["status: running"]:::job RUNNING --> LOOP["Per-record loop —
isolated try/catch per item"] LOOP --> DONE["status: completed
payload = results[]"]:::job LOOP -- "OAuth token genuinely invalid" --> FAILED["status: failed
lastError set"]:::job
Notice
  • The concurrency guard exists because two overlapping runs used to race: both would search MYOB/HubSpot for an existing record before either one's write became visible, and both would create it — a real duplicate-record bug this fixed.
  • Per-record isolation means one bad invoice or customer (a deleted MYOB record, a malformed line item) shows up as a single failed entry in the results — it doesn't take down the other few hundred records in the same run.
Sync · MYOB → HubSpot

Pulling from MYOB

Every object type pages fully through MYOB's NextPageLink before any matching starts, then each record is matched against HubSpot by whatever stable key that object type has.

flowchart TD
  classDef myob fill:#E7E2F5,stroke:#7C5CBF,color:#2E1F4D
  classDef hs fill:#F3D9C9,stroke:#C85A35,color:#5A2E15
  classDef decision fill:#FBEFD1,stroke:#C99A3D,color:#5A4212

  FETCH["Fetch from MYOB
(paged via NextPageLink)"]:::myob FETCH --> P["Products
Inventory/Item"]:::myob FETCH --> C["Customers
Contact/Customer"]:::myob FETCH --> I["Invoices
Sale/Invoice/Item"]:::myob P --> P1{"Match by hs_sku"}:::decision P1 -- found --> P2["Patch HubSpot product"]:::hs P1 -- "not found" --> P3["Create HubSpot product"]:::hs C --> C1{"Match by MYOB DisplayID
(fallback: email or name)"}:::decision C1 -- found --> C2["Patch contact or company"]:::hs C1 -- "not found" --> C3["Create contact or company"]:::hs I --> I1{"Sync record for this
MYOB invoice number?"}:::decision I1 -- "yes, HubSpot copy active" --> I2["Update status + amount"]:::hs I1 -- "yes, but copy is archived" --> I3["Clear stale record,
fall through to recreate"]:::hs I1 -- "no record" --> I4{"Active HubSpot invoice
with same number?"}:::decision I4 -- "yes, it was pushed FROM HubSpot" --> I5["Skip — already linked
the other direction"]:::hs I4 -- "yes, unlinked" --> I6["Link it (recovers a
lost sync record)"]:::hs I4 -- no --> I7["Create HubSpot invoice
+ line items + associations"]:::hs
Notice
  • Customer matching prefers the MYOB DisplayID over email specifically because many MYOB individual customers have no email at all — email-only matching used to block large-scale sync entirely.
  • The "already linked the other direction" branch matters: without it, an invoice that was pushed to MYOB from HubSpot would get a second, contradictory sync record every time this pull ran.
Sync · HubSpot → MYOB

Pushing to MYOB

The mirror direction, cursor-paged from HubSpot. Invoices get an extra gate up front — a draft is often incomplete, and MYOB has no "draft" concept of its own.

flowchart TD
  classDef hs fill:#F3D9C9,stroke:#C85A35,color:#5A2E15
  classDef myob fill:#E7E2F5,stroke:#7C5CBF,color:#2E1F4D
  classDef decision fill:#FBEFD1,stroke:#C99A3D,color:#5A4212

  FETCH["Fetch from HubSpot
(cursor-paged)"]:::hs FETCH --> P["Products"]:::hs FETCH --> C["Contacts & Companies"]:::hs FETCH --> I["Invoices"]:::hs P --> P1{"Match by MYOB item Number
(= hs_sku)"}:::decision P1 -- found --> P2["Update item —
preserve IsBought/IsSold,
merge SellingDetails"]:::myob P1 -- "not found" --> P3["Create item —
income account fallback,
verify before retrying a timeout"]:::myob C --> C1{"Match by MYOB DisplayID"}:::decision C1 -- found --> C2["Update customer —
retry once on RowVersion conflict"]:::myob C1 -- "not found" --> C3["Create customer —
verify before retrying a timeout"]:::myob I --> G{"Still a draft in HubSpot?"}:::decision G -- "yes, drafts off (default)" --> SKIP["Skip — a draft's total
can misleadingly read $0"]:::hs G -- no --> ORIGIN["Origin check —
see next diagram"]:::decision ORIGIN --> UPDATE["Correct Number if changed,
apply payment if paid"]:::myob ORIGIN --> CREATE["Create invoice —
lines priced from HubSpot's own
amount + resolved tax code"]:::myob
Notice
  • Line pricing is derived from HubSpot's own amount field rather than recomputed from price × discount% — that field is authoritative regardless of how the discount was actually applied in HubSpot.
  • Tax code comes from whatever's already resolved on the matching MYOB item, not recalculated per invoice — so a product marked tax-free in MYOB stays tax-free on every invoice line, automatically.
Reference

Field-level mapping

What actually moves for each object, and which HubSpot properties exist only because this integration created them. Every custom property lives in HubSpot's "Tendy MYOB Integration" group; everything else was already a stock HubSpot property.

Contacts & companies
HubSpot propertyApplies toKindMYOB fieldDirection
emailContactsnativeAddresses[0].EmailMYOB → HubSpot
firstnameContactsnativeFirstNameMYOB → HubSpot
lastnameContactsnativeLastNameMYOB → HubSpot
nameCompaniesnativeCompanyNameMYOB → HubSpot
domainCompaniesnativeAddresses[0].WebsiteMYOB → HubSpot
phone, address, city, state, zip, countryBothnativeAddresses[0].{Phone1, Street, City, State, PostCode, Country}MYOB → HubSpot
tendy_myob_customer_display_idBothcustomDisplayIDboth
tendy_myob_sale_layoutBothdropdownSellingDetails.SaleLayoutboth
tendy_myob_invoice_deliveryBothdropdownSellingDetails.InvoiceDeliveryboth
tendy_myob_item_price_levelBothdropdownSellingDetails.ItemPriceLevelboth
tendy_myob_tax_code_uidBothcustomSellingDetails.TaxCode.UIDboth
tendy_myob_freight_tax_code_uidBothcustomSellingDetails.FreightTaxCode.UIDboth
tendy_myob_use_customer_tax_codeBothboolSellingDetails.UseCustomerTaxCodeboth
tendy_myob_abn / _abn_branchBothcustomSellingDetails.ABN / ABNBranchboth
Products
HubSpot propertyKindMYOB fieldDirectionNote
namenativeNameboth
descriptionnativeDescriptionboth
pricenativeSellingDetails.BaseSellingPriceboth
hs_skunativeNumberboththe matching key both directions search by
tendy_myob_item_uidcustomUIDbothwritten by whichever side creates it — never read back for matching
tendy_myob_tax_code_uiddropdownSellingDetails.TaxCode.UIDboth
tendy_myob_income_account_uidcustomIncomeAccount.UIDboth
Invoice line items
HubSpot propertyKindMYOB fieldDirectionNote
namenativeDescription / Item.NameMYOB → HubSpot
pricenativeUnitPricebothused as a fallback when amount isn't authoritative
quantitynativeShipQuantityboth
hs_skunativeItem.NumberHubSpot → MYOBinherited from the associated product, not set directly on the line
amountnative(derives UnitPrice on create)HubSpot → MYOBHubSpot computes this from price/qty/discount — treated as the authoritative total
hs_discount_percentagenativeDiscountPercentboth
hs_product_idnative—MYOB → HubSpotassociation only, not a MYOB field
tendy_myob_income_account_uidcustom——defined in the property group but not currently populated by either sync
Invoices
HubSpot propertyKindMYOB fieldDirectionNote
hs_numbernativeNumberboththe matching key both directions search by
hs_invoice_datenativeDateboth
hs_due_datenativeTerms.BalanceDueDateMYOB → HubSpot
hs_invoice_statusnativeStatus / BalanceDueAmountbothdrives the draft gate and the paid-payment check on the push side
hs_payment_datenativePayment.DateHubSpot → MYOB
hs_amount_billednativeTotalAmountMYOB → HubSpot
hs_currency, hs_invoice_billablenativeForeignCurrency.CurrencyCode / —MYOB → HubSpotset once at creation, never revisited on resync
Notice
  • Invoices have no custom HubSpot properties at all. Which side created an invoice, and whether the two copies are still linked, lives entirely in the MyobSyncRecord Postgres table — see the next diagram.
  • A "both" direction property is written by the MYOB→HubSpot pull whenever MYOB has a value, and read back by the HubSpot→MYOB push as an override — editing one of these directly on a HubSpot record changes what gets sent to MYOB next time it pushes.
Deep dive

Invoice origin tracking & self-healing

The trickiest part of the system: deciding what to do when a linked invoice disappears from one side. The answer depends entirely on which system created it first — recorded permanently in MyobSyncRecord.

flowchart TD
  classDef decision fill:#FBEFD1,stroke:#C99A3D,color:#5A4212
  classDef danger fill:#F6D9D9,stroke:#C85A5A,color:#5A1414
  classDef safe fill:#DCEEE1,stroke:#4C9A6A,color:#1D4A2E
  classDef hs fill:#F3D9C9,stroke:#C85A35,color:#5A2E15

  START["HubSpot invoice due for push"]:::hs
  START --> D{"Direct record exists?
(hs-to-myob-invoice)"}:::decision D -- yes --> V{"Fetch by MYOB UID —
still exists?"}:::decision V -- yes --> RESYNC["Resync: correct Number,
apply payment"]:::safe V -- "no (404)" --> PROVEN["The direct record IS the proof:
this invoice started in HubSpot"]:::safe PROVEN --> RECREATE["Recreate in MYOB —
reverse-record check is skipped,
it would be a false signal here"]:::safe D -- no --> R{"Reverse record exists?
(invoice, from a MYOB→HS pull)"}:::decision R -- no --> CREATE_NEW["Genuinely new — create in MYOB"]:::safe R -- yes --> F{"Still findable by
MYOB invoice number?"}:::decision F -- yes --> LINK["Link + resync —
it exists, just missing
the direct record"]:::safe F -- no --> RESPECT["Originated in MYOB,
deleted there — do NOT recreate"]:::danger
Notice — two bugs this shape had to survive
  • A spurious reverse record. The MYOB→HubSpot pull has a fallback matcher that links by invoice number when its own sync record is missing — but it used to write that link unconditionally, even for invoices that were actually pushed FROM HubSpot. That gave HubSpot-originated invoices a reverse record they had no business having.
  • Checking the wrong record first. A direct record proves HubSpot origin on its own — it should never be second-guessed by a reverse record that might be that same spurious artifact. The fix was ordering: once a direct record has proven origin, the reverse-record check is skipped entirely for that invoice, not just deprioritized.
Commerce

Billing

Stripe is the source of truth for subscription state — the backend only ever reacts to its webhooks, it never infers billing status from anything else.

sequenceDiagram
  participant Wizard as Setup Wizard
  participant Backend
  participant Stripe

  Wizard->>Backend: GET /billing/status?portalId
  Backend-->>Wizard: trial / active / past_due / canceled

  alt Starting a subscription
    Wizard->>Backend: POST /billing/checkout-session
    Backend->>Stripe: create Checkout Session
(trial_end carried over if still trialing) Backend-->>Wizard: session URL Wizard->>Stripe: complete checkout Stripe->>Backend: webhook: checkout.session.completed Backend->>Backend: updateSubscriptionFromCheckoutSession() else Managing an existing plan Wizard->>Backend: GET /billing/portal-session Backend->>Stripe: create Billing Portal session Backend-->>Wizard: portal URL end Stripe->>Backend: webhook: subscription.updated / payment_failed Backend->>Backend: updateSubscriptionFromStripeSubscription()
Notice
  • The 14-day trial starts automatically on install — no card required until the trial actually ends, which is why trial_end is passed through to Stripe rather than charging immediately at checkout.
  • The webhook route is mounted before express.json() in server.js specifically so Stripe's signature check gets the raw, unparsed body it needs.