HubSpot
You can enable the HubSpot wrapper right from the Supabase dashboard.
Open wrapper in dashboardHubSpot is a developer and marketer of software products for inbound marketing, sales, and customer service.
The HubSpot Wrapper is a WebAssembly(Wasm) foreign data wrapper which allows you to read data from your HubSpot for use within your Postgres database.
Available Versions#
| Version | Wasm Package URL | Checksum | Required Wrappers Version |
|---|---|---|---|
| 0.2.0 | https://github.com/supabase/wrappers/releases/download/wasm_hubspot_fdw_v0.2.0/hubspot_fdw.wasm | 223f0e8d7557bd24f51b58fb89dcd3c1431719105acca0754ce35dfd1139296a | >=0.5.0 |
| 0.1.0 | https://github.com/supabase/wrappers/releases/download/wasm_hubspot_fdw_v0.1.0/hubspot_fdw.wasm | 2cbf39e9e28aa732a225db09b2186a2342c44697d4fa047652d358e292ba5521 | >=0.4.0 |
Preparation#
Before you can query HubSpot, you need to enable the Wrappers extension and store your credentials in Postgres.
Enable Wrappers#
Make sure the wrappers extension is installed on your database:
1create extension if not exists wrappers with schema extensions;Enable the HubSpot Wrapper#
Enable the Wasm foreign data wrapper:
1create foreign data wrapper wasm_wrapper2 handler wasm_fdw_handler3 validator wasm_fdw_validator;About Authentication
HubSpot deprecated their legacy API Keys in November 2022. The
api_key
option in this wrapper accepts a
Private App Access Token
, which is HubSpot's recommended authentication method. See
for setup instructions.
Store your credentials (optional)#
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server in plain text. Anyone with access to this table will be able to view these credentials. Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
1-- Save your HubSpot private apps access token in Vault and retrieve the created `key_id`2select vault.create_secret(3 '<HubSpot access token>', -- HubSpot private apps access token4 'hubspot', -- secret name for api_key_name lookup5 'HubSpot private apps access token for Wrappers'6);The secret name (e.g., 'hubspot') can be used with api_key_name for environment-agnostic configuration.
Connecting to HubSpot#
We need to provide Postgres with the credentials to access HubSpot and any additional options. We can do this using the create server command:
1create server hubspot_server2 foreign data wrapper wasm_wrapper3 options (4 fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_hubspot_fdw_v0.1.0/hubspot_fdw.wasm',5 fdw_package_name 'supabase:hubspot-fdw',6 fdw_package_version '0.1.0',7 fdw_package_checksum '2cbf39e9e28aa732a225db09b2186a2342c44697d4fa047652d358e292ba5521',8 api_url 'https://api.hubapi.com/crm/v3', -- optional9 api_key_id '<key_ID>' -- The Key ID from above.10 );Note the fdw_package_* options are required, which specify the Wasm package metadata. You can get the available package version list from above.
Create a schema#
We recommend creating a schema to hold all the foreign tables:
1create schema if not exists hubspot;Options#
The full list of foreign table options are below:
object- Object name in HubSpot, required.
Supported objects are listed below:
| Object name |
|---|
objects/companies |
objects/contacts |
objects/deals |
objects/feedback_submissions |
objects/goal_targets |
objects/leads |
objects/line_items |
objects/<objectType> |
objects/partner_clients |
objects/products |
objects/tickets |
The objectType in objects/<objectType> must be substituted with an object type ID, e.g. a custom object 2-3508482.
Entities#
Below are all the entities supported by this FDW. Each entity must have id, created_at, updated_at and attrs columns, the other columns can be any properties defined on the corresponding HubSpot object. For example, if there is a custom property user_id defined on the Contacts object, the table DDL can be:
1create foreign table hubspot.contacts (2 id text,3 user_id text,4 created_at timestamp,5 updated_at timestamp,6 attrs jsonb7)8 server hubspot_server9 options (10 object 'objects/contacts'11 );The column user_id is the custom property internal name, which can be found in the Details section of Edit property page on HubSpot Settings -> Data Management -> Properties.
We can use SQL import foreign schema to import foreign table definitions from HubSpot.
For example, using below SQL can automatically create foreign tables in the hubspot schema.
1-- create all the foreign tables2import foreign schema hubspot from server hubspot_server into hubspot;34-- or, create selected tables only5import foreign schema hubspot6 limit to ("contact", "companies")7 from server hubspot_server into hubspot;89-- or, create all foreign tables except selected tables10import foreign schema hubspot11 except ("contacts")12 from server hubspot_server into hubspot;The objects table will not be created by the import foreign schema statement.
Companies#
This is object represents the companies and organizations that interact with your business.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| companies | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.companies (2 id text,3 name text,4 domain text,5 created_at timestamp,6 updated_at timestamp,7 attrs jsonb8)9 server hubspot_server10 options (11 object 'objects/companies'12 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Contacts#
This is object represents the contacts.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| contacts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.contacts (2 id text,3 email text,4 firstname text,5 lastname text,6 created_at timestamp,7 updated_at timestamp,8 attrs jsonb9)10 server hubspot_server11 options (12 object 'objects/contacts'13 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Deals#
This is object represents the transactions with contacts and/or companies.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| deals | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.deals (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/deals'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Feedback submissions#
This is object represents the information submitted to your NPS, CSAT, CES, and custom feedback surveys.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| feedback_submissions | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.feedback_submissions (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/feedback_submissions'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Goals#
This is object represents the user-specific quotas for their sales and services teams based on templates provided by HubSpot.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| goal_targets | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.goals (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/goal_targets'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Leads#
This is object represents the contacts or companies that are potential customers who have shown interest in your products or services.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| leads | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.leads (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/leads'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Deals#
This is object represents the instances of products to deals and quotes.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| line_items | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.line_items (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/line_items'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Objects#
This is object represents the objects included in all accounts, such as contacts and companies, as well as for custom objects.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
<objectType> | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.objects (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/<objectType>' -- objectType can be a custom objec type id, e.g. `2-3508482`10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Partner clients#
This is object represents the customers that Solutions Partners have a sold or managed relationship with.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| partner_clients | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.partner_clients (2 id text,3 created_at timestamp,4 updated_at timestamp,5 attrs jsonb6)7 server hubspot_server8 options (9 object 'objects/partner_clients'10 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Products#
This is object represents the collection of goods and services that your company offers.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| products | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.products (2 id text,3 name text,4 created_at timestamp,5 updated_at timestamp,6 attrs jsonb7)8 server hubspot_server9 options (10 object 'objects/products'11 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Tickets#
This is object represents the customer service requests in your CRM.
Ref: HubSpot API docs
Operations#
| Object | Select | Insert | Update | Delete | Truncate |
|---|---|---|---|---|---|
| tickets | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage#
1create foreign table hubspot.tickets (2 id text,3 subject text,4 created_at timestamp,5 updated_at timestamp,6 attrs jsonb7)8 server hubspot_server9 options (10 object 'objects/tickets'11 );Notes#
- The
attrscolumn contains additional user attributes in JSON format
Query Pushdown Support#
where clause pushdown#
This FDW supports where id = 'xxx' clause pushdown for all entities. For example,
1select * from hubspot.contacts where id = '1504';limit clause pushdown#
This FDW supports limit clause pushdown for all the entities. For example,
1select * from hubspot.contacts limit 200;Supported Data Types#
| Postgres Data Type | HubSpot Data Type |
|---|---|
| boolean | Boolean |
| bigint | Number |
| double precision | Number |
| numeric | Number |
| text | String |
| timestamp | Time |
| timestamptz | Time |
| jsonb | Json |
The HubSpot API uses JSON formatted data, please refer to HubSpot API docs for more details.
Limitations#
This section describes important limitations and considerations when using this FDW:
- Large result sets may experience slower performance due to full data transfer requirement
- Query pushdown support limited to 'id' columns only
- Materialized views using these foreign tables may fail during logical backups
Examples#
Below are some examples on how to use HubSpot foreign tables.
Basic example#
This example will create a "foreign table" inside your Postgres database and query its data.
1create foreign table hubspot.contacts (2 id text,3 email text,4 firstname text,5 lastname text,6 created_at timestamp,7 updated_at timestamp,8 attrs jsonb9)10 server hubspot_server11 options (12 object 'objects/contacts'13 );1415-- query all contacts16select * from hubspot.contacts;1718-- query one contact19select * from hubspot.contacts20where id = '1501';attrs is a special column which stores all the object attributes in JSON format, you can extract any attributes needed from it. See more examples below.
Query JSON attributes#
1-- extract `archived` flag2select attrs->>'archived' as is_archived3from hubspot.contacts4where id = '1501';Query custom properties#
1-- suppose the Contacts object has a custom property 'user_id', we can2-- define it as a column in the foreign table3create foreign table hubspot.contacts (4 id text,5 email text,6 firstname text,7 lastname text,8 user_id text,9 created_at timestamp,10 updated_at timestamp,11 attrs jsonb12)13 server hubspot_server14 options (15 object 'objects/contacts'16 );1718select id, user_id from hubspot.contacts19where id = '1501';Note that the column user_id is the custom property internal name, not its display name. It can be found in the Details section of Edit property page on HubSpot Settings -> Data Management -> Properties.
Query custom objects#
Suppose we have a HubSpot custom object Projects and its object type id is 2-3508482. It also has a custom property name, we can define the foreign table and query it as below:
1create foreign table hubspot.custom_projects (2 id text,3 name text,4 created_at timestamp,5 updated_at timestamp,6 attrs jsonb7)8 server hubspot_server9 options (10 object 'objects/2-3508482'11 );1213select * from hubspot.custom_projects;Note that custom object type id 2-3508482 can be found in page URL on HubSpot Settings -> Data Management -> Custom Objects. For example,
1https://app.hubspot.com/sales-products-settings/17328329/object/2-3508482