HubSpot (Apps step)
HubSpot
Lists, searches, reads, creates and updates HubSpot CRM records: contacts, companies, deals, tickets, products and line items.
Use it to connect the plant to sales: list the deals closed this week for production planning, find a company by its domain, or create a ticket when a customer shipment has a problem.
Beta. This step has not yet been checked against a live HubSpot account, so treat its first runs as a test, and tell us if an operation does not answer as described.
Find it in the workflow editor's palette under Apps. See Apps steps for what every Apps step has in common.
Set it up
- In HubSpot, open Settings › Integrations › Private Apps (Development › Legacy apps in newer accounts), create a private app with the CRM scopes the workflow needs, such as crm.objects.contacts.read and crm.objects.contacts.write, and copy its access token.
- In DataMagik, open Script Engine › Credentials and add a "Bearer Token" credential holding the access token.
- Add api.hubapi.com to Allowed Domains in the workflow's Script settings.
Credential: A Bearer Token credential holding a HubSpot private app access token, or an OAuth 2.0 credential for a HubSpot public app.
Signing in with OAuth 2.0
| Grant type | Sign in with the provider (authorization code). Save the credential, then click Connect on it. |
| Sign-in (authorization) URL | https://app.hubspot.com/oauth/authorize |
| Token URL | https://api.hubapi.com/oauth/v1/token |
| Scope | crm.objects.contacts.read crm.objects.contacts.write crm.objects.companies.read crm.objects.deals.read oauth |
Register the Redirect URI the credential form shows in the provider's app settings.
Create a public app in your HubSpot developer account, add the credential's Redirect URI to its redirect URLs and use its client id and secret. The scopes above are an example: ask for the read and write scopes of the objects the workflow uses (crm.objects.deals.write to update deals, tickets for tickets…), and set the same ones on the app.
Hosts it calls: api.hubapi.com
Operations
| Operation | What it does |
|---|---|
| Object › List | Lists every record of an object type, following every page up to the step's page limit. |
| Object › Get | Reads one record by its id. |
| Object › Create | Creates a record of an object type. |
| Object › Update | Changes properties on one record; properties you leave out keep their values. |
| Object › Search | Finds records whose properties match filters; returns one page of results. |
Object › List
Lists every record of an object type, following every page up to the step's page limit.
Calls GET /{objectType}. Follows the pages, up to Most pages (10 unless you change it).
| Field | Required | What to put |
|---|---|---|
| Object type | Yes | The kind of CRM record. One of: Contacts, Companies, Deals, Tickets, Products, Line items. |
| Properties to return | No | Comma-separated internal property names; leave empty for HubSpot's default few. For example dealname,amount,dealstage,closedate. |
| Limit | No | Records per request (HubSpot's limit is 100, the default 10). For example 10. |
| Archived only | No | On lists the archived (deleted) records instead of the active ones. |
What comes out: One item per record: {{ $json.id }}, {{ $json.properties }} with the properties asked for, such as {{ $json.properties.dealname }}, and {{ $json.createdAt }} and {{ $json.updatedAt }}.
Example: List deals with properties dealname,amount,dealstage,closedate and keep the closed-won ones for the weekly production forecast.
Object › Get
Reads one record by its id.
Calls GET /{objectType}/{objectId}.
| Field | Required | What to put |
|---|---|---|
| Object type | Yes | The kind of CRM record. One of: Contacts, Companies, Deals, Tickets, Products, Line items. |
| Record id | Yes | The record's HubSpot id (its Record ID, the number in its HubSpot address). For example 51. |
| Properties to return | No | Comma-separated internal property names; leave empty for HubSpot's default few. For example dealname,amount,dealstage,closedate. |
What comes out: One item: the record, with {{ $json.id }}, {{ $json.properties }} and {{ $json.updatedAt }}.
Example: Read company {{ $json.hubspot_company_id }} with properties name,domain,city before printing its shipping label.
Object › Create
Creates a record of an object type.
Calls POST /{objectType}.
| Field | Required | What to put |
|---|---|---|
| Object type | Yes | The kind of CRM record. One of: Contacts, Companies, Deals, Tickets, Products, Line items. |
| Properties | Yes | A JSON object of internal property names and values for the new record. For example {"subject": "Damaged shipment {{ $json.shipper }}", "hs_pipeline": "0", "hs_pipeline_stage": "1"}. |
What comes out: One item: the new record, with {{ $json.id }}, {{ $json.properties }} and {{ $json.createdAt }}.
Example: Create a ticket with subject Damaged shipment {{ $json.shipper }} when the receiving inspection fails, then save {{ $json.id }} with the shipper.
Object › Update
Changes properties on one record; properties you leave out keep their values.
Calls PATCH /{objectType}/{objectId}.
| Field | Required | What to put |
|---|---|---|
| Object type | Yes | The kind of CRM record. One of: Contacts, Companies, Deals, Tickets, Products, Line items. |
| Record id | Yes | The record's HubSpot id (its Record ID, the number in its HubSpot address). For example 51. |
| Properties | Yes | A JSON object of the internal property names to change and their new values; an empty string clears a property. For example {"dealstage": "closedwon"}. |
What comes out: One item: the record as it now is, with {{ $json.id }}, {{ $json.properties }} and {{ $json.updatedAt }}.
Example: When the order ships, update deal {{ $json.hubspot_deal_id }} with {"ship_date": "{{ $json.ship_date }}"} (a custom date property).
Object › Search
Finds records whose properties match filters; returns one page of results.
Calls POST /{objectType}/search.
| Field | Required | What to put |
|---|---|---|
| Object type | Yes | The kind of CRM record. One of: Contacts, Companies, Deals, Tickets, Products, Line items. |
| Filter groups | Yes | A JSON list of filter groups: the filters in one group must all match, and a record matching any group is returned. Operators include EQ, NEQ, GT, LT, CONTAINS_TOKEN and HAS_PROPERTY. For example [{"filters": [{"propertyName": "domain", "operator": "EQ", "value": "{{ $json.domain }}"}]}]. |
| Properties to return (list) | No | A JSON list of internal property names to return; leave empty for HubSpot's default few. For example ["name", "domain", "city"]. |
| Limit | No | How many records to return (HubSpot's limit is 200, the default 10). For example 10. |
What comes out: One item per record found: {{ $json.id }}, {{ $json.properties }} and {{ $json.updatedAt }}.
Example: Search companies where domain EQ {{ $json.customer_domain }} to find the HubSpot company for a Plex customer.
Trigger: HubSpot: New Items
Under Triggers in the palette. It looks at HubSpot on a schedule (every 15 minutes unless you change Look every) with one of these operations: Object › List, and starts the workflow with the items it has not seen on an earlier look, one item each. Saving the workflow sets up the schedule.
- New means: not seen before, by the item's id (or the field you name in Item field), or newer than the newest one last time, by a date or increasing number.
- On the first run it only remembers what is there, unless you choose Start with everything.
- Test runs show what would be new without remembering it. It remembers the last 5000 ids, so filter the list to keep it shorter than that.
Example
A shipment confirmation feeds HubSpot › Search on deals with a filter on the deal's PO number property, then HubSpot › Update sets the deal's shipped date to {{ $json.ship_date }}.
Tips
- HubSpot only returns a few default properties (such as email, firstname and lastname for a contact); name the others in Properties to return.
- Use each property's internal name, not its label: Settings › Properties shows it next to the label (dealstage, closedate, hs_object_id).
- Search finds up to 10,000 records and returns one page; put {"after": "<the next page's value>"} in More body fields to get the next page.
- It calls HubSpot on test runs too, so create and update records in a test account while building.
Settings every Apps step has
- More query parameters: any query parameter the fields do not offer, sent as is.
- More body fields: a JSON object merged into the request body; nested objects merge, other values replace.
- Most requests per second: spaces the calls out for rate limits. A "too many requests" (429) answer is retried after the wait the API asks for.
- Most pages: for operations that follow pages, the most pages to fetch (10 unless you change it, up to 100). The run warns when it stops with more to get.
- Fail on a non-2xx response: on by default. Turn it off to handle errors yourself.
HubSpot's own API documentation: https://developers.hubspot.com/docs/api/crm/understanding-the-crm