Skip to content

feat(hubspot): add upsert contacts operation - #10775

Open
zain2983 wants to merge 2 commits into
simstudioai:stagingfrom
zain2983:feat/hubspot-upsert-contacts
Open

zain2983 wants to merge 2 commits into
simstudioai:stagingfrom
zain2983:feat/hubspot-upsert-contacts

Conversation

@zain2983

@zain2983 zain2983 commented Dec 4, 2026 •

Copy link
Copy Markdown

Closes #10777

Summary

Adds hubspot_upsert_contacts (HubSpot block operation Upsert Contacts): create or update up to 100 contacts in one call to POST /crm/v3/objects/contacts/batch/upsert, matched by email (default) or a custom unique property.

Why: syncing a list of contacts today means one search plus one create-or-update per contact, and a retry can create a duplicate between the search and the create. The batch upsert makes the same call safe to repeat.

  • One invalid contact rejects the whole batch (HTTP 400, the tool throws HubSpot's message).
  • With a custom unique property as ID Property, and a distinct objectWriteTraceId on every contact, HubSpot saves the valid contacts and returns 207; the tool reports errors, numErrors and success: false (the step itself completes, so branch on success). With email, HubSpot's contacts guide says partial upserts are not supported, and production portals answer 400 to trace IDs ("Cannot perform a partial upsert with email"): one invalid contact rejects the whole batch. The tool's descriptions say so; it does not block trace IDs with email, so HubSpot's own error reaches the user.
  • Checked before any request is sent, each error naming the contact's position: 1 to 100 contacts, each with an id and a properties object, no repeated id (email compared without case), trace IDs on all contacts or none and all distinct, and no property that contradicts the id. The 100 limit is HubSpot's; the repeated-id and trace-ID rules come from a HubSpot developer test account, where HubSpot answered 400 (for a repeated email, with the vaguer "Contact already exists"). HubSpot's reference doesn't state them.
  • dryRunOutput returns the previewed contacts plus success: true, numErrors: 0, errors: [] (without them Sim's sampler filled numErrors with 900000001).
  • Results come back in no guaranteed order (observed); match them on email or objectWriteTraceId.
  • No retry is configured (no HubSpot tool configures one). A 429 throws HubSpot's message; a workflow can retry the block.
  • Observation, against the documented behaviour: on a HubSpot developer test account, a traced batch with email as ID Property returned 207 and saved the valid contact, twice. Treat that as the exception, not the contract (see above).

Product update (if relevant)

HubSpot users can sync a list of contacts in one step without searching first to decide between create and update. No rollout or plan restriction in Sim. Docs: the HubSpot integration page.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

macOS arm64, Bun 1.4.4, Node 24.

In the product. Sim built from this branch, run in dev mode against its own Postgres (pgvector) and Redis. A synthetic user and workspace were created with Sim's auth routes. The HubSpot credential is Sim's own HubSpot service key credential type (sim credentials create hubspot-service-account), holding a private-app token for a HubSpot developer test account; no OAuth app was involved. The workflow (Start, HubSpot Upsert Contacts, Response) was written with the workflow SDK and run through Sim's executor with sim workflows run --manual (dry run: sim workflows run --dry). Synthetic contacts only (@example.com, phones +1 201-555-01xx); all were archived afterwards. Each result was checked in HubSpot with a batch read, not from the tool's output alone.

# Case Result
1 3 new contacts pass: 3 records, new: true
2 same 3, jobtitle only pass: same IDs, new: false, other properties kept
3 one invalid email, no trace IDs pass: run failed with HubSpot's message; the valid contact was not saved
4a custom unique ID Property, trace IDs on all, one invalid email pass: 207, valid one saved, bad one in errors with its trace ID, success: false
4b email ID Property, trace IDs on all, one invalid developer test account only: 207, valid one saved (HubSpot documents this as unsupported; see above)
5 custom unique idProperty (a test property created for this) pass: create then update, same records
6 101 contacts pass: refused before any request, "(got 101)"
7 dry run pass: nothing written; stubbed request and clean success/numErrors/errors (this showed the 900000001 bug, fixed)
8 empty list; missing id; list given as an object; invalid JSON; properties as a JSON string; id with spaces and capitals; blank idProperty pass
8 same email twice (also differing in case) before: HubSpot 400, "Contact already exists". Now refused locally, naming both positions
8 trace IDs on some contacts only, or repeated before: HubSpot 400. Now refused locally
8 boolean and numeric property values, null HubSpot accepted and stored them as text (observation)
8 unknown property; unknown idProperty HubSpot 400 with its message, surfaced as is

Not run live: a real 429 or 5xx. Sim's executor throws on a non-2xx response with HubSpot's message before the tool's response code runs, so the tool has no code of its own for them. The live runs were on the tree before the last wording-only edits (descriptions and comments); the code paths they exercise did not change.
Run output was read from the CLI and checked in HubSpot; the workflow was not run from the UI.

Gate, after the final rebase onto staging at 6b9613a1: bun run generate (clean tree), lint:check, type-check, check:audits and check-block-registry origin/staging passed. HubSpot and block tests: 27 passed, of which upsert_contacts.test.ts is 15; 10 of those 15 fail against the previous version of the tool.
Full suite (turbo run test --continue --concurrency=1), run on staging at b0e9ae17, two staging commits before the final rebase (neither touches HubSpot, the registries or generated tool files): 24 of 25 tasks passed (@sim/app 3,887 files and 46,421 tests passed, 13 skipped; sim 1,412; @sim/realtime 194; @sim/workflow-code 846). The one failure is @sim/desktop, which cannot build its native module here (no C headers for this Node); this change does not touch it. Not rerun after the last rebase.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

None yet.

@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@zain2983 is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

Create or update up to 100 contacts in one request, matched by email or a
custom unique property, through HubSpot's batch upsert endpoint.

One invalid contact rejects the whole batch. With a custom unique ID property and an
objectWriteTraceId on every contact, HubSpot saves the valid ones and answers 207; the
tool returns those errors with success false instead of dropping them.
Found by running the block through Sim's executor against a HubSpot
developer test account:

- dry run: return success, numErrors and errors; without them Sim's
  sampler filled numErrors with 900000001
- refuse before sending, naming the contact's position: a repeated id
  (email compared without case; HubSpot answered "Contact already
  exists"), trace IDs on only some contacts or repeated, a non-object
  entry, a non-text id or trace ID, a property that contradicts the id
- report the size of an oversized batch
- say that partial success (objectWriteTraceId on every contact) needs
  a custom unique ID Property: HubSpot's guide does not support partial
  upserts with email
- give the block its own ID Property field for Upsert Contacts, with the
  right placeholder, and restore the shared placeholder
- json-array generation for the Contacts wand
- document that results come back in no guaranteed order

Tests cover each guard; 10 of the 15 fail against the previous tool.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant