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 } from "@trigger.dev/sdk";
2
import { createHash } from "crypto";
3
4
// Go to your normal HubSpot account
5
// Create a private app in Settings > Integrations > Private apps
6
// With scopes: 'crm.objects.contacts.read', 'crm.objects.contacts.write'
7
// And add your trigger webhooks url in target url.
8
// Create subscription for contact creation and deletion
9
// Copy your client secret from the Auth tab and paste it in the .env file
10
// Create an HTTP Endpoint, with the HubSpot details
11
const hubspot = client.defineHttpEndpoint({
12
id: "hubspot",
13
source: "hubspot.com",
14
icon: "hubspot",
15
verify: async (request) => {
16
const bodyText = await request.text();
17
const source_string = process.env.HUBSPOT_SECRET! + bodyText;
18
const hash = createHash("sha256").update(source_string).digest("hex");
19
const reqHash = request.headers.get("X-HubSpot-Signature");
20
const success = hash === reqHash;
21
if (success) return { success };
22
return { success: false, reason: "Failed sha256 verification" };
23
},
24
});
25
26
// Job that runs when the HTTP endpoint is called from HubSpot
27
// When a contact is created or deleted
28
client.defineJob({
29
id: "http-hubspot",
30
name: "HTTP HubSpot",
31
version: "1.0.0",
32
enabled: true,
33
// Create a trigger from the HTTP endpoint
34
trigger: hubspot.onRequest(),
35
run: async (request, io, ctx) => {
36
const body = await request.json();
37
await io.logger.info(`Body`, body);
38
},
39
});