Back to APIs

Manage marketing, sales, and service data in HubSpot.

Using the HubSpot API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your HubSpot background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using HubSpot

Below are some working code examples of how you can use HubSpot with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import { Client } from "@hubspot/api-client";
3
import z from "zod";
4
5
// SDK: https://github.com/hubspot/hubspot-api-nodejs
6
// API Reference: https://developers.hubspot.com/docs/api/overview
7
// Create an private app in HubSpot and get access token : https://developers.hubspot.com/docs/api/private-apps
8
const hubspot = new Client({ accessToken: process.env.HUBSPOT_ACCESS_TOKEN });
9
10
client.defineJob({
11
id: "hubspot-create-contact",
12
name: "HubSpot Create Contact",
13
version: "1.0.0",
14
trigger: eventTrigger({
15
name: "hubspot-create-contact",
16
schema: z.object({
17
firstname: z.string(),
18
lastname: z.string(),
19
email: z.string().email(),
20
}),
21
}),
22
run: async (payload, io, ctx) => {
23
const { firstname, lastname, email } = payload;
24
25
await io.runTask(
26
"Create HubSpot Contact",
27
async () => {
28
// Create a contact in HubSpot
29
await hubspot.crm.contacts.basicApi.create({
30
properties: { firstname, lastname, email },
31
associations: [], // Optional
32
});
33
},
34
35
// Add metadata to improve how the task displays in the logs
36
{ name: "Create HubSpot Contact", icon: "hubspot" }
37
);
38
},
39
});