HubSpot
Server-side event delivery to HubSpot via the official @hubspot/api-client SDK. Sends custom behavioral events, updates contact properties via the CRM API, and batches events through the collector's config.batch.
HubSpot is a server destination in the walkerOS flow:
Receives events server-side from the collector, resolves contact identity (email or objectId), optionally updates contact properties, then sends the custom event to HubSpot.
Installation
npm install @walkeros/collector @walkeros/server-destination-hubspot- Integrated
- Bundled
import { startFlow } from '@walkeros/collector';
import destinationHubspot from '@walkeros/server-destination-hubspot';
await startFlow({
destinations: {
hubspot: {
code: destinationHubspot,
config: {
settings: {
accessToken: process.env.HUBSPOT_ACCESS_TOKEN,
eventNamePrefix: 'YOUR_EVENT_NAME_PREFIX',
},
},
},
},
});
A complete flow.json with this destination:
{
"version": 4,
"flows": {
"default": {
"config": {
"platform": "server"
},
"destinations": {
"hubspot": {
"package": "@walkeros/server-destination-hubspot",
"config": {
"settings": {
"accessToken": "$secret.HUBSPOT_ACCESS_TOKEN",
"eventNamePrefix": "YOUR_EVENT_NAME_PREFIX"
}
}
}
}
}
}
}Configuration
This destination uses the standard destination config wrapper (consent, data, env, id, ...). For the shared fields see destination configuration. Package-specific fields live under config.settings and are listed below.
Settings
| Property | Type | Description | More |
|---|---|---|---|
accessToken | string | HubSpot private app access token. Create one in HubSpot Settings > Integrations > Private Apps. Requires analytics.behavioral_events.send scope. | |
eventNamePrefix | string | Fully qualified event name prefix: pe{HubID}_ (e.g. pe12345678_). Find it in HubSpot under Data Management > Custom Events. | |
email | string | walkerOS mapping value path to resolve contact email from events (like user.email). Default: user.email. An event needs an email or an objectId. | |
objectId | string | walkerOS mapping value path to resolve HubSpot CRM objectId from events. Alternative to email for contact association. | |
identify | any | Destination-level contact update mapping. Resolves to { email, properties } and updates the contact with that email (not an upsert). Fires on first push and re-fires when values change. | |
defaultProperties | Record<string, string> | Static event properties added to every event occurrence. Useful for hs_touchpoint_source, hs_page_content_type, etc. |
Mapping
Per-event rules under config.mapping. For the standard rule fields (consent, condition, data, batch, name, policy) see mapping.
| Property | Type | Description | More |
|---|---|---|---|
eventName | string | Override eventName for this rule. Without the prefix -- just the event name part (e.g. purchase_completed). The eventNamePrefix is prepended automatically. | |
identify | any | Per-event contact update by email. Resolves to { email, properties }. Overrides destination-level identify. Use with silent: true on login/identify events. | |
properties | any | Additional event properties mapping. Resolved values are merged with defaultProperties and serialized to strings. |
Examples
Default event
A walker event is sent to HubSpot as a custom behavioral event keyed by the user email.
{
"name": "product view",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420,
"currency": "EUR"
},
"context": {
"shopping": [
"detail",
0
]
},
"globals": {
"pagegroup": "shop"
},
"custom": {
"completely": "random"
},
"user": {
"email": "user@example.com"
},
"nested": [],
"consent": {
"functional": true
},
"id": "db22fb16c70f663d",
"trigger": "load",
"entity": "product",
"action": "view",
"timestamp": 1700000100000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}events.send.basicApi.send({
"eventName": "pe12345678_product_view",
"email": "user@example.com",
"occurredAt": {},
"properties": {}
})Default properties
Destination-level settings.defaultProperties are merged into every HubSpot event payload, such as traffic source metadata.
{
"name": "page view",
"data": {
"domain": "www.example.com",
"title": "walkerOS documentation",
"referrer": "https://www.walkeros.io/",
"search": "?foo=bar",
"hash": "#hash",
"id": "/docs/"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"pagegroup": "docs"
},
"custom": {
"completely": "random"
},
"user": {
"email": "user@example.com"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "f0cc5f6fec3d8eeb",
"trigger": "load",
"entity": "page",
"action": "view",
"timestamp": 1700000102000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}events.send.basicApi.send({
"eventName": "pe12345678_page_view",
"email": "user@example.com",
"occurredAt": {},
"properties": {
"hs_touchpoint_source": "walkerOS",
"hs_page_content_type": "STANDARD_PAGE"
}
})Destination identify
With settings.identify mapping the email and name properties, the destination updates the HubSpot contact by email before sending the behavioral event.
{
"name": "page view",
"data": {
"domain": "www.example.com",
"title": "walkerOS documentation",
"referrer": "https://www.walkeros.io/",
"search": "?foo=bar",
"hash": "#hash",
"id": "/docs/"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"pagegroup": "docs"
},
"custom": {
"completely": "random"
},
"user": {
"email": "user@example.com",
"firstName": "Jane",
"lastName": "Doe"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "f0cc5f6fec3d8eeb",
"trigger": "load",
"entity": "page",
"action": "view",
"timestamp": 1700000103000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}crm.contacts.basicApi.update("user@example.com", {
"properties": {
"firstname": "Jane",
"lastname": "Doe"
}
}, "email");
events.send.basicApi.send({
"eventName": "pe12345678_page_view",
"email": "user@example.com",
"occurredAt": {},
"properties": {}
})Custom event name
A mapping supplies a custom HubSpot event name and maps order data into properties for the behavioral event.
{
"name": "order complete",
"data": {
"value": 99.5,
"currency": "EUR",
"id": "ord-123"
},
"context": {
"shopping": [
"complete",
0
]
},
"globals": {
"pagegroup": "shop"
},
"custom": {
"completely": "random"
},
"user": {
"email": "user@example.com"
},
"nested": [
{
"entity": "product",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "product",
"data": {
"id": "cc",
"name": "Cool Cap",
"size": "one size",
"price": 42
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "gift",
"data": {
"name": "Surprise"
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
}
],
"consent": {
"functional": true
},
"id": "235d0d7bd7a213f2",
"trigger": "load",
"entity": "order",
"action": "complete",
"timestamp": 1700000101000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}{
"name": "order complete",
"settings": {
"eventName": "purchase_completed",
"properties": {
"map": {
"revenue": "data.value",
"currency": "data.currency",
"order_id": "data.id"
}
}
}
}events.send.basicApi.send({
"eventName": "pe12345678_purchase_completed",
"email": "user@example.com",
"occurredAt": {},
"properties": {
"revenue": "99.5",
"currency": "EUR",
"order_id": "ord-123"
}
})Object id association
With settings.objectId set to user.id, the HubSpot event is associated via objectId instead of email.
{
"name": "product view",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420,
"currency": "EUR"
},
"context": {
"shopping": [
"detail",
0
]
},
"globals": {
"pagegroup": "shop"
},
"custom": {
"completely": "random"
},
"user": {
"id": "hs-contact-789"
},
"nested": [],
"consent": {
"functional": true
},
"id": "db22fb16c70f663d",
"trigger": "load",
"entity": "product",
"action": "view",
"timestamp": 1700000105000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}events.send.basicApi.send({
"eventName": "pe12345678_product_view",
"objectId": "hs-contact-789",
"occurredAt": {},
"properties": {}
})User login identify
A user login only updates the HubSpot contact by email with profile and lifecycle properties, skipping the event send.
{
"name": "user login",
"data": {
"email": "login@acme.com",
"first_name": "Jane",
"last_name": "Doe",
"lifecycle": "lead"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"lang": "elb"
},
"custom": {
"completely": "random"
},
"user": {
"email": "user@example.com"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "523e1d817e08d2c8",
"trigger": "test",
"entity": "user",
"action": "login",
"timestamp": 1700000104000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}{
"silent": true,
"settings": {
"identify": {
"map": {
"email": "data.email",
"properties": {
"map": {
"firstname": "data.first_name",
"lastname": "data.last_name",
"lifecyclestage": "data.lifecycle"
}
}
}
}
}
}crm.contacts.basicApi.update("login@acme.com", {
"properties": {
"firstname": "Jane",
"lastname": "Doe",
"lifecyclestage": "lead"
}
}, "email")When it fails
- no identity: A product view event without email or objectId cannot be associated with a HubSpot contact: the push fails with missing-input instead of counting as delivered. Reported as
failedwith codemissing-input. - no identity login: A user login event without email or objectId cannot be associated with a HubSpot contact: the push fails with missing-input instead of counting as delivered. Reported as
failedwith codemissing-input. - no identity order: A order complete event without email or objectId cannot be associated with a HubSpot contact: the push fails with missing-input instead of counting as delivered. Reported as
failedwith codemissing-input. - no identity page: A page view event without email or objectId cannot be associated with a HubSpot contact: the push fails with missing-input instead of counting as delivered. Reported as
failedwith codemissing-input.
Consent
The quickstart sets no config.consent, so HubSpot receives every event, whatever consent the event carries. To send only events with consent, add consent: { marketing: true } to config, next to settings (with several keys listed, one granted key is enough). An event without that consent is skipped or queued, depending on the collector's consentDenied. Server flows built by the CLI skip it and count it in skipped. With startFlow it waits in the destination's queue by default: a later event that carries consent does not release it, and only a walker consent command does, which then sends the waiting events of every user at once. Pass consentDenied: 'skip' to startFlow to skip such events instead (see Gate a destination with consent and consent-denied events on a server).
Identity
Every event must be associated with a contact via email or objectId. The email path defaults to user.email. An event where neither value can be resolved fails with the missing-input code, and a failed HubSpot call fails the push with HubSpot's HTTP status. A 429 and a 5xx answer are retryable.
Batching
Set config.batch to send events through HubSpot's batch API instead of one
request per event. The options are in
Batch scheduling. A flush sends chunks of
500 events, and each event keeps its own outcome.
"config": {
"batch": { "size": 100, "wait": 5000 },
"settings": {
"accessToken": "$secret.HUBSPOT_ACCESS_TOKEN",
"eventNamePrefix": "YOUR_EVENT_NAME_PREFIX"
}
}A batched event answers queued with the reason batch. A failed flush is
reported (one ERROR line, the failed counter, the dead-letter queue), but the
producer's message is not redelivered.
Contact update
Use the identify setting (destination-level or per-rule) to update HubSpot contact properties alongside event tracking. The resolved mapping must produce { email, properties }, and the destination updates the contact with that email (not an upsert). When HubSpot refuses the update, the push fails with HubSpot's status and the event itself is not sent. When the mapping resolves without an email, the destination skips the update and logs it at DEBUG only; the event is still sent. State-based dedup prevents redundant API calls when identity has not changed.