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.
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
- 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.
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
- 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.
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
- 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.
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
- 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.
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
- 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.
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.
| HubSpot property | Applies to | Kind | MYOB field | Direction |
|---|---|---|---|---|
| Contacts | native | Addresses[0].Email | MYOB → HubSpot | |
| firstname | Contacts | native | FirstName | MYOB → HubSpot |
| lastname | Contacts | native | LastName | MYOB → HubSpot |
| name | Companies | native | CompanyName | MYOB → HubSpot |
| domain | Companies | native | Addresses[0].Website | MYOB → HubSpot |
| phone, address, city, state, zip, country | Both | native | Addresses[0].{Phone1, Street, City, State, PostCode, Country} | MYOB → HubSpot |
| tendy_myob_customer_display_id | Both | custom | DisplayID | both |
| tendy_myob_sale_layout | Both | dropdown | SellingDetails.SaleLayout | both |
| tendy_myob_invoice_delivery | Both | dropdown | SellingDetails.InvoiceDelivery | both |
| tendy_myob_item_price_level | Both | dropdown | SellingDetails.ItemPriceLevel | both |
| tendy_myob_tax_code_uid | Both | custom | SellingDetails.TaxCode.UID | both |
| tendy_myob_freight_tax_code_uid | Both | custom | SellingDetails.FreightTaxCode.UID | both |
| tendy_myob_use_customer_tax_code | Both | bool | SellingDetails.UseCustomerTaxCode | both |
| tendy_myob_abn / _abn_branch | Both | custom | SellingDetails.ABN / ABNBranch | both |
| HubSpot property | Kind | MYOB field | Direction | Note |
|---|---|---|---|---|
| name | native | Name | both | |
| description | native | Description | both | |
| price | native | SellingDetails.BaseSellingPrice | both | |
| hs_sku | native | Number | both | the matching key both directions search by |
| tendy_myob_item_uid | custom | UID | both | written by whichever side creates it — never read back for matching |
| tendy_myob_tax_code_uid | dropdown | SellingDetails.TaxCode.UID | both | |
| tendy_myob_income_account_uid | custom | IncomeAccount.UID | both |
| HubSpot property | Kind | MYOB field | Direction | Note |
|---|---|---|---|---|
| name | native | Description / Item.Name | MYOB → HubSpot | |
| price | native | UnitPrice | both | used as a fallback when amount isn't authoritative |
| quantity | native | ShipQuantity | both | |
| hs_sku | native | Item.Number | HubSpot → MYOB | inherited from the associated product, not set directly on the line |
| amount | native | (derives UnitPrice on create) | HubSpot → MYOB | HubSpot computes this from price/qty/discount — treated as the authoritative total |
| hs_discount_percentage | native | DiscountPercent | both | |
| hs_product_id | native | — | MYOB → HubSpot | association only, not a MYOB field |
| tendy_myob_income_account_uid | custom | — | — | defined in the property group but not currently populated by either sync |
| HubSpot property | Kind | MYOB field | Direction | Note |
|---|---|---|---|---|
| hs_number | native | Number | both | the matching key both directions search by |
| hs_invoice_date | native | Date | both | |
| hs_due_date | native | Terms.BalanceDueDate | MYOB → HubSpot | |
| hs_invoice_status | native | Status / BalanceDueAmount | both | drives the draft gate and the paid-payment check on the push side |
| hs_payment_date | native | Payment.Date | HubSpot → MYOB | |
| hs_amount_billed | native | TotalAmount | MYOB → HubSpot | |
| hs_currency, hs_invoice_billable | native | ForeignCurrency.CurrencyCode / — | MYOB → HubSpot | set once at creation, never revisited on resync |
- 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.
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
- 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.
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()
- 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.