Skip to content

Commit 84d93e2

Browse files
Adam Goughwaleed
authored andcommitted
fixed payload and added hubspot triggers
1 parent 1658484 commit 84d93e2

19 files changed

Lines changed: 3446 additions & 222 deletions

apps/sim/blocks/blocks/hubspot.ts

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
44
import type { HubSpotResponse } from '@/tools/hubspot/types'
55
import { getTrigger } from '@/triggers'
6+
import { hubspotAllTriggerOptions } from '@/triggers/hubspot/utils'
67

78
export const HubSpotBlock: BlockConfig<HubSpotResponse> = {
89
type: 'hubspot',
@@ -735,10 +736,33 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
735736
generationType: 'json-object',
736737
},
737738
},
738-
...getTrigger('hubspot_contact_created').subBlocks,
739+
{
740+
id: 'selectedTriggerId',
741+
title: 'Trigger Type',
742+
type: 'dropdown',
743+
mode: 'trigger',
744+
options: hubspotAllTriggerOptions,
745+
value: () => 'hubspot_contact_created',
746+
required: true,
747+
},
748+
...getTrigger('hubspot_contact_created').subBlocks.slice(1),
739749
...getTrigger('hubspot_contact_deleted').subBlocks.slice(1),
740750
...getTrigger('hubspot_contact_privacy_deleted').subBlocks.slice(1),
741751
...getTrigger('hubspot_contact_property_changed').subBlocks.slice(1),
752+
...getTrigger('hubspot_company_created').subBlocks.slice(1),
753+
...getTrigger('hubspot_company_deleted').subBlocks.slice(1),
754+
...getTrigger('hubspot_company_property_changed').subBlocks.slice(1),
755+
...getTrigger('hubspot_conversation_creation').subBlocks.slice(1),
756+
...getTrigger('hubspot_conversation_deletion').subBlocks.slice(1),
757+
...getTrigger('hubspot_conversation_new_message').subBlocks.slice(1),
758+
...getTrigger('hubspot_conversation_privacy_deletion').subBlocks.slice(1),
759+
...getTrigger('hubspot_conversation_property_changed').subBlocks.slice(1),
760+
...getTrigger('hubspot_deal_created').subBlocks.slice(1),
761+
...getTrigger('hubspot_deal_deleted').subBlocks.slice(1),
762+
...getTrigger('hubspot_deal_property_changed').subBlocks.slice(1),
763+
...getTrigger('hubspot_ticket_created').subBlocks.slice(1),
764+
...getTrigger('hubspot_ticket_deleted').subBlocks.slice(1),
765+
...getTrigger('hubspot_ticket_property_changed').subBlocks.slice(1),
742766
],
743767
tools: {
744768
access: [
@@ -883,26 +907,53 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
883907
paging: { type: 'json', description: 'Pagination info with next/prev cursors' },
884908
metadata: { type: 'json', description: 'Operation metadata' },
885909
success: { type: 'boolean', description: 'Operation success status' },
886-
// Trigger outputs
887-
eventId: { type: 'string', description: 'Unique webhook event ID' },
888-
subscriptionId: { type: 'string', description: 'Webhook subscription ID' },
889-
portalId: { type: 'string', description: 'HubSpot portal (account) ID' },
890-
occurredAt: { type: 'string', description: 'Event occurrence timestamp' },
891-
eventType: { type: 'string', description: 'Type of event that occurred' },
892-
objectId: { type: 'string', description: 'ID of the affected object' },
893-
propertyName: {
894-
type: 'string',
895-
description: 'Name of changed property (for property change events)',
910+
payload: {
911+
type: 'json',
912+
description: 'Full webhook payload array from HubSpot containing event details',
896913
},
897-
propertyValue: {
914+
provider: {
898915
type: 'string',
899-
description: 'New value of property (for property change events)',
916+
description: 'Provider name (hubspot)',
900917
},
901-
changeSource: {
902-
type: 'string',
903-
description: 'Source of the change (CRM, API, WORKFLOW, etc.)',
918+
providerConfig: {
919+
appId: {
920+
type: 'string',
921+
description: 'HubSpot App ID',
922+
},
923+
clientId: {
924+
type: 'string',
925+
description: 'HubSpot Client ID',
926+
},
927+
triggerId: {
928+
type: 'string',
929+
description: 'Trigger ID (e.g., hubspot_company_created)',
930+
},
931+
clientSecret: {
932+
type: 'string',
933+
description: 'HubSpot Client Secret',
934+
},
935+
developerApiKey: {
936+
type: 'string',
937+
description: 'HubSpot Developer API Key',
938+
},
939+
curlSetWebhookUrl: {
940+
type: 'string',
941+
description: 'curl command to set webhook URL',
942+
},
943+
curlCreateSubscription: {
944+
type: 'string',
945+
description: 'curl command to create subscription',
946+
},
947+
webhookUrlDisplay: {
948+
type: 'string',
949+
description: 'Webhook URL display value',
950+
},
951+
propertyName: {
952+
type: 'string',
953+
description: 'Optional property name filter (for property change triggers)',
954+
},
904955
},
905-
},
956+
} as any,
906957
triggerAllowed: true,
907958
triggers: {
908959
enabled: true,
@@ -911,6 +962,20 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
911962
'hubspot_contact_deleted',
912963
'hubspot_contact_privacy_deleted',
913964
'hubspot_contact_property_changed',
965+
'hubspot_company_created',
966+
'hubspot_company_deleted',
967+
'hubspot_company_property_changed',
968+
'hubspot_conversation_creation',
969+
'hubspot_conversation_deletion',
970+
'hubspot_conversation_new_message',
971+
'hubspot_conversation_privacy_deletion',
972+
'hubspot_conversation_property_changed',
973+
'hubspot_deal_created',
974+
'hubspot_deal_deleted',
975+
'hubspot_deal_property_changed',
976+
'hubspot_ticket_created',
977+
'hubspot_ticket_deleted',
978+
'hubspot_ticket_property_changed',
914979
],
915980
},
916981
}

apps/sim/lib/webhooks/utils.server.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -811,31 +811,9 @@ export async function formatWebhookInput(
811811
})
812812

813813
return {
814-
eventId: event.eventId,
815-
subscriptionId: event.subscriptionId,
816-
portalId: event.portalId,
817-
occurredAt: event.occurredAt,
818-
eventType: event.subscriptionType,
819-
attemptNumber: event.attemptNumber,
820-
objectId: event.objectId,
821-
changeSource: event.changeSource,
822-
changeFlag: event.changeFlag,
823-
appId: event.appId,
824-
825-
propertyName: event.propertyName,
826-
propertyValue: event.propertyValue,
827-
sourceId: event.sourceId,
828-
829-
webhook: {
830-
data: {
831-
provider: 'hubspot',
832-
path: foundWebhook.path,
833-
providerConfig: foundWebhook.providerConfig,
834-
payload: body,
835-
headers: Object.fromEntries(request.headers.entries()),
836-
method: request.method,
837-
},
838-
},
814+
payload: body,
815+
provider: 'hubspot',
816+
providerConfig: foundWebhook.providerConfig,
839817
workflowId: foundWorkflow.id,
840818
}
841819
}
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
import { HubspotIcon } from '@/components/icons'
2+
import type { TriggerConfig } from '@/triggers/types'
3+
import {
4+
buildCompanyCreatedOutputs,
5+
hubspotCompanyTriggerOptions,
6+
hubspotSetupInstructions,
7+
} from './utils'
8+
9+
export const hubspotCompanyCreatedTrigger: TriggerConfig = {
10+
id: 'hubspot_company_created',
11+
name: 'HubSpot Company Created',
12+
provider: 'hubspot',
13+
description: 'Trigger workflow when a new company is created in HubSpot',
14+
version: '1.0.0',
15+
icon: HubspotIcon,
16+
17+
subBlocks: [
18+
{
19+
id: 'selectedTriggerId',
20+
title: 'Trigger Type',
21+
type: 'dropdown',
22+
mode: 'trigger',
23+
options: hubspotCompanyTriggerOptions,
24+
value: () => 'hubspot_company_created',
25+
required: true,
26+
},
27+
{
28+
id: 'clientId',
29+
title: 'Client ID',
30+
type: 'short-input',
31+
placeholder: 'Enter your HubSpot app Client ID',
32+
description: 'Found in your HubSpot app settings under Auth tab',
33+
required: true,
34+
mode: 'trigger',
35+
condition: {
36+
field: 'selectedTriggerId',
37+
value: 'hubspot_company_created',
38+
},
39+
},
40+
{
41+
id: 'clientSecret',
42+
title: 'Client Secret',
43+
type: 'short-input',
44+
placeholder: 'Enter your HubSpot app Client Secret',
45+
description: 'Found in your HubSpot app settings under Auth tab',
46+
password: true,
47+
required: true,
48+
mode: 'trigger',
49+
condition: {
50+
field: 'selectedTriggerId',
51+
value: 'hubspot_company_created',
52+
},
53+
},
54+
{
55+
id: 'appId',
56+
title: 'App ID',
57+
type: 'short-input',
58+
placeholder: 'Enter your HubSpot App ID',
59+
description: 'Found in your HubSpot app settings. Used to identify your app.',
60+
required: true,
61+
mode: 'trigger',
62+
condition: {
63+
field: 'selectedTriggerId',
64+
value: 'hubspot_company_created',
65+
},
66+
},
67+
{
68+
id: 'developerApiKey',
69+
title: 'Developer API Key',
70+
type: 'short-input',
71+
placeholder: 'Enter your HubSpot Developer API Key',
72+
description: 'Used for making API calls to HubSpot. Found in your HubSpot app settings.',
73+
password: true,
74+
required: true,
75+
mode: 'trigger',
76+
condition: {
77+
field: 'selectedTriggerId',
78+
value: 'hubspot_company_created',
79+
},
80+
},
81+
{
82+
id: 'webhookUrlDisplay',
83+
title: 'Webhook URL',
84+
type: 'short-input',
85+
readOnly: true,
86+
showCopyButton: true,
87+
useWebhookUrl: true,
88+
placeholder: 'Webhook URL will be generated',
89+
description: 'Copy this URL and paste it into your HubSpot app webhook subscription settings',
90+
mode: 'trigger',
91+
condition: {
92+
field: 'selectedTriggerId',
93+
value: 'hubspot_company_created',
94+
},
95+
},
96+
{
97+
id: 'triggerInstructions',
98+
title: 'Setup Instructions',
99+
type: 'text',
100+
defaultValue: hubspotSetupInstructions(
101+
'company.creation',
102+
'The webhook will trigger whenever a new company is created in your HubSpot account, regardless of the source (manual entry, form submission, API, import, etc.).'
103+
),
104+
mode: 'trigger',
105+
condition: {
106+
field: 'selectedTriggerId',
107+
value: 'hubspot_company_created',
108+
},
109+
},
110+
{
111+
id: 'curlSetWebhookUrl',
112+
title: '1. Set Webhook Target URL',
113+
type: 'code',
114+
language: 'javascript',
115+
value: (params: Record<string, any>) => {
116+
const webhookUrl = params.webhookUrlDisplay || '{YOUR_WEBHOOK_URL_FROM_ABOVE}'
117+
return `curl -X PUT "https://api.hubapi.com/webhooks/v3/{YOUR_APP_ID}/settings?hapikey={YOUR_DEVELOPER_API_KEY}" \\
118+
-H "Content-Type: application/json" \\
119+
-d '{
120+
"targetUrl": "${webhookUrl}",
121+
"throttling": {
122+
"maxConcurrentRequests": 10
123+
}
124+
}'`
125+
},
126+
readOnly: true,
127+
collapsible: true,
128+
defaultCollapsed: true,
129+
showCopyButton: true,
130+
description: 'Run this command to set your webhook URL in HubSpot',
131+
mode: 'trigger',
132+
condition: {
133+
field: 'selectedTriggerId',
134+
value: 'hubspot_company_created',
135+
},
136+
},
137+
{
138+
id: 'curlCreateSubscription',
139+
title: '2. Create Webhook Subscription',
140+
type: 'code',
141+
language: 'javascript',
142+
defaultValue: `curl -X POST "https://api.hubapi.com/webhooks/v3/{YOUR_APP_ID}/subscriptions?hapikey={YOUR_DEVELOPER_API_KEY}" \\
143+
-H "Content-Type: application/json" \\
144+
-d '{
145+
"eventType": "company.creation",
146+
"active": true
147+
}'`,
148+
readOnly: true,
149+
collapsible: true,
150+
defaultCollapsed: true,
151+
showCopyButton: true,
152+
description: 'Run this command to subscribe to company creation events',
153+
mode: 'trigger',
154+
condition: {
155+
field: 'selectedTriggerId',
156+
value: 'hubspot_company_created',
157+
},
158+
},
159+
{
160+
id: 'triggerSave',
161+
title: '',
162+
type: 'trigger-save',
163+
mode: 'trigger',
164+
triggerId: 'hubspot_company_created',
165+
condition: {
166+
field: 'selectedTriggerId',
167+
value: 'hubspot_company_created',
168+
},
169+
},
170+
{
171+
id: 'samplePayload',
172+
title: 'Event Payload Example',
173+
type: 'code',
174+
language: 'json',
175+
defaultValue: JSON.stringify(
176+
[
177+
{
178+
eventId: 3181526815,
179+
subscriptionId: 4629975,
180+
portalId: 244315265,
181+
appId: 23608917,
182+
occurredAt: 1762659213730,
183+
subscriptionType: 'company.creation',
184+
attemptNumber: 0,
185+
objectId: 316126906050,
186+
changeFlag: 'CREATED',
187+
changeSource: 'CRM_UI',
188+
sourceId: 'userId:84916424',
189+
},
190+
],
191+
null,
192+
2
193+
),
194+
readOnly: true,
195+
collapsible: true,
196+
defaultCollapsed: true,
197+
mode: 'trigger',
198+
condition: {
199+
field: 'selectedTriggerId',
200+
value: 'hubspot_company_created',
201+
},
202+
},
203+
],
204+
205+
outputs: buildCompanyCreatedOutputs(),
206+
207+
webhook: {
208+
method: 'POST',
209+
headers: {
210+
'Content-Type': 'application/json',
211+
'X-HubSpot-Signature': 'sha256=...',
212+
'X-HubSpot-Request-Id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
213+
'User-Agent': 'HubSpot Webhooks',
214+
},
215+
},
216+
}

0 commit comments

Comments
 (0)