hubspot_upsert_contact
HubSpot write medium risk
Part of the HubSpot Agent.
What it does
Idempotently create-or-update a single HubSpot contact keyed by email address. If a contact with the given email exists it is updated in place; otherwise a new contact is created. Maps to the contacts batch/upsert endpoint with idProperty=email so repeated calls with the same email are safe and never produce duplicates. Key inputs: email (the dedupe key; trimmed and lowercased before send, and a blank value or one without '@' is refused before any preview) plus a properties object of HubSpot contact properties by internal name: standard ones such as firstname, lastname, company, jobtitle, phone, lifecyclestage, hs_lead_status; any other property must already exist in the portal and be passed by its internal name, else HubSpot rejects the commit (PROPERTY_DOESNT_EXIST). Returns the standard envelope {success:true,data} where data is {applied, result}; result is {id, created, properties} - id: the contact id; created: HubSpot's `new` flag (true = a new contact was created, false = an existing one was updated); properties: the values HubSpot returned, less its association and note counts (such as hs_num_associated_open_deals and num_notes), which HubSpot recalculates after the write. An HTTP 207 answer is a failure, not a success: the tool returns HubSpot's error and writes no audit row. The tool takes no associations - to associate, call hubspot_associate_objects with the returned id. Use this to land a client's own LinkedIn lead as a CRM contact, or to keep an existing contact in sync during the nightly sync. Two-phase (ADR-028/029, the same gate as Google and LinkedIn writes): the first call (no preview_id) builds the request locally and returns a preview_id - nothing is sent to HubSpot; after the user approves that preview in a later message, re-call with that preview_id and identical arguments to COMMIT (single-use, 30 min; a changed, forged or replayed token fails closed). Where consent_confirmed exists it must be true at preview and at commit. [POLICY] Contact data written here may be the client's OWN leads only, used solely for the authorizing client and only for consented purposes; never enrich, append, or verify a profile against third-party or LinkedIn member data, never build a cross-account or prospecting database, never commingle data across clients. Hash PII where the destination supports it; honor deletion-on-request; respect member retention windows (profile <=24h, social activity <=48h caches). [REMINDER] Upsert is idempotent by email -- one logical contact per email; preview the field map and confirm consent before writing. [WHEN TO USE] Use when you must persist or refresh a single client-owned contact in HubSpot from an approved, consented source (e.g., a consented LinkedIn lead or a known correction); do NOT use to mass-load purchased or appended lists.
When to use it
Use to persist or refresh a single client-owned contact in HubSpot from an approved, consented source; do NOT use for purchased/appended/prospecting lists.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
email | string | yes | Email address used as the upsert key (idProperty=email). Trimmed and lowercased before send; a blank value or one without '@' is refused before any preview. HubSpot's own validation rejects any other malformed address. |
properties | object | yes | HubSpot contact property map to set/update by internal name, e.g. {firstname, lastname, company, jobtitle, phone, lifecyclestage, hs_lead_status}; any other property must already exist in the portal, else HubSpot rejects the commit (PROPERTY_DOESNT_EXIST). email may be omitted here since it is the key. |
consent_confirmed | boolean | yes | Must be true to proceed: caller attests this is the client's own lead/contact with a lawful basis/consent to store. False blocks the write. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Write ONLY the authorizing client's own contacts/leads, used solely for that client and only for consented purposes. NEVER enrich/append/verify a profile, build a cross-account or prospecting lead database, or commingle data across clients. Hash PII where the destination supports it. Honor deletion-on-request and member-derived data retention (profile <=24h, social activity <=48h caches).
Reminder
Idempotent by email -- one logical contact per email; preview the field map and confirm consent before writing.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
auth | HubSpot rejected the request: invalid or expired OAuth token / session (401 Unauthorized). | Refresh the HubSpot OAuth access token (or reconnect the integration); do not retry with the same token. Surface that the connection must be re-authorized. | no |
permission | Token lacks the crm.objects.contacts.write scope or the portal denied access (403 Forbidden). | Grant crm.objects.contacts.write to the HubSpot app and reconnect; surface the exact missing scope to the user. | no |
validation | HubSpot 400: a property is invalid/read-only/malformed, or email is missing/blank for the idProperty key. Surface HubSpot's exact message and the offending propertyName. | Fix the property name/value (e.g., valid lifecyclestage internal value, non-empty well-formed email) and re-preview before re-upserting. Do not retry verbatim. | no |
rate_limit | HubSpot 429 Too Many Requests (TEN_SECONDLY_ROLLING or daily policy). Burst limit ~100-110 req/10s per installed account. | Honor X-HubSpot-RateLimit-* headers / Retry-After; exponential backoff with jitter; serialize nightly-sync writes. | yes |
not_found | Referenced unique property or portal object not found (404). | Verify idProperty exists in the portal; for email upsert this is rare -- inspect and surface the returned message. | no |
platform | HubSpot server error (500/502/503) -- transient platform fault. | Retry with exponential backoff; if persistent, surface that HubSpot is unavailable and re-queue -- do not silently drop the lead. | yes |
invalid_argument | HubSpot API 2026-09 enforces this portal's validation rules on every write (conditionally required properties, properties required at creation, the Edit Associations permission). A violation is a 400 VALIDATION_ERROR: when errors[].code is MISSING_* the tool returns invalid_argument naming the rule and the property; any other invalid value returns invalid_argument with HubSpot's own message. | Supply the property the rule names, or fix the value HubSpot's message names (HubSpot internal property names), then re-preview. For "Missing 'Edit Associations' permission." no argument change helps: a HubSpot admin must give the user who connected Scalix the Edit Associations permission (Settings > Users & Teams), then re-preview. | no |
Edge cases
- Idempotent upsert: same email called twice updates the existing contact, never creates a duplicate.
- Partial upserts are not supported when using email as the idProperty for contacts. Scalix sends exactly one contact per call.
- The tool takes no associations (batch/upsert creates none); to associate, call hubspot_associate_objects with the returned id.
- Email casing/whitespace: Scalix trims and lowercases the email before the preview is made, so the preview and the request carry the same normalised address.
- Secondary emails: a contact may own multiple emails; upsert keys on the supplied email and may match an existing record via a secondary email.
- A 207 multi-status answer means this contact was not upserted: the tool returns HubSpot's error (a VALIDATION_ERROR maps to invalid_argument, as a 400 does) and writes no audit row.
- Retention/consent: if consent_confirmed is false or the source is member-derived beyond retention, block the write and explain why.