- Fetch a list of companies from HubSpot.
- For each company, fetch its associated contacts.
- Combine this data into a nested structure where each company object contains an array of its contacts.
Note: All config objects for individual workflow steps support the full ApiConfig schema. superglue infers most fields, but you can provide explicit configurations if needed. Workflows themselves are defined and then executed.
Prerequisites
- A HubSpot account with API access.
- A HubSpot Private App and its Access Token (recommended for authentication).
- superglue SDK installed and configured (see Quick Start).
Installation
Ensure you have the superglue client and Zod for schema definition:Authentication
HubSpot’s API uses Bearer token authentication. The simplest way is to create a Private App in your HubSpot developer account and use its Access Token. Keep this token handy; you’ll provide it as a credential when executing the workflow.Define Output Schemas with Zod
We’ll define the structure for individual contacts and companies, and then a final schema for the combined data.Building the Workflow
We’ll useclient.buildWorkflow()
to instruct superglue to create the necessary steps. superglue will analyze the HubSpot API (using the provided documentation URL) and the instruction to figure out how to fetch companies, then contacts for each company, and combine them.
buildWorkflow
is called:
- superglue analyzes the
instruction
and theintegrations
(HubSpot API documentation). - It designs a sequence of steps: one to fetch companies, and then a looping mechanism or subsequent steps to fetch contacts for each company using associations.
- It determines the necessary API endpoints (e.g.,
/crm/v3/objects/companies
,/crm/v3/objects/contacts
, and how to query associations). - It generates transformations to fit the data into
hubspotDataSchema
.
workflow
object returned contains the definition of these steps, including the generated ApiConfig
objects for each API call.
Executing the Workflow
Once the workflow is built, you can execute it usingclient.executeWorkflow()
. You’ll provide the workflow definition (or its ID if previously saved/upserted) and the necessary runtime credentials.
Expected Output (Simplified)
Theresult.data
from a successful execution would look something like this:
Additional Notes
- Error Handling: The workflow will automatically retry failed steps and provide detailed error information for debugging.
- Pagination: HubSpot APIs are automatically paginated by superglue when building workflows.
- Rate Limiting: superglue handles HubSpot’s rate limits automatically.
- Data Mapping: The JSONata transformations are automatically generated and cached for performance.
- Saving Workflows: You can save the
builtWorkflow
definition usingclient.upsertWorkflow(workflow.id, workflow)
for later execution by ID.
Further Exploration
- Multi-Integration Workflows: Combine HubSpot data with other services, or integrate HubSpot data with other integrations in a single workflow.
- Explore the API Reference for Workflows and Types for more details.