Skip to content

Commit 9539dd4

Browse files
committed
Add HubSpot Workflow Management Actions
- Implemented new actions for managing workflows in HubSpot, including: - Create a new workflow - Retrieve workflow details - Retrieve emails associated with a workflow - Retrieve multiple workflows by their IDs - Retrieve migrated workflow mappings - Update an existing workflow - Delete a workflow - Added corresponding methods in the hubspot.app.mjs for API interactions. - Updated constants and added necessary props for each action.
1 parent 5040561 commit 9539dd4

File tree

9 files changed

+379
-0
lines changed

9 files changed

+379
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-create-workflow",
5+
name: "Create a New Workflow",
6+
description: "Create a new workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.21",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
name: {
12+
type: "string",
13+
label: "Workflow Name",
14+
description: "The name of the workflow to create",
15+
},
16+
type: {
17+
type: "string",
18+
label: "Workflow Type",
19+
description: "The type of workflow to create",
20+
options: [
21+
{
22+
label: "DRIP",
23+
value: "DRIP",
24+
},
25+
{
26+
label: "SIMPLE",
27+
value: "SIMPLE",
28+
},
29+
{
30+
label: "COMPLEX",
31+
value: "COMPLEX",
32+
},
33+
],
34+
},
35+
description: {
36+
type: "string",
37+
label: "Description",
38+
description: "Description of the workflow",
39+
optional: true,
40+
},
41+
triggerType: {
42+
type: "string",
43+
label: "Trigger Type",
44+
description: "The type of trigger for the workflow",
45+
optional: true,
46+
},
47+
},
48+
async run({ $ }) {
49+
const {
50+
name, type, description, triggerType,
51+
} = this;
52+
53+
const workflowData = {
54+
name,
55+
type,
56+
...(description && {
57+
description,
58+
}),
59+
...(triggerType && {
60+
triggerType,
61+
}),
62+
};
63+
64+
const response = await this.hubspot.createWorkflow({
65+
data: workflowData,
66+
$,
67+
});
68+
69+
$.export("$summary", `Successfully created workflow: ${name}`);
70+
return response;
71+
},
72+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-delete-workflow",
5+
name: "Delete a Workflow",
6+
description: "Delete a workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.21",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
workflowId: {
12+
type: "string",
13+
label: "Workflow ID",
14+
description: "The ID of the workflow to delete",
15+
},
16+
},
17+
async run({ $ }) {
18+
const { workflowId } = this;
19+
20+
const response = await this.hubspot.deleteWorkflow({
21+
workflowId,
22+
$,
23+
});
24+
25+
$.export("$summary", `Successfully deleted workflow ${workflowId}`);
26+
return response;
27+
},
28+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import hubspot from "../../hubspot.app.mjs";
3+
4+
export default {
5+
key: "hubspot-retrieve-batch-workflows",
6+
name: "Retrieve a Batch of Workflows",
7+
description: "Retrieve multiple workflows by their IDs. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
hubspot,
12+
workflowIds: {
13+
propDefinition: [
14+
hubspot,
15+
"workflowId",
16+
],
17+
type: "string[]",
18+
label: "Workflow IDs",
19+
description: "A list of workflow IDs to retrieve",
20+
},
21+
},
22+
async run({ $ }) {
23+
const workflows = [];
24+
const parsedWorkflowIds = parseObject(this.workflowIds);
25+
26+
for (const workflowId of parsedWorkflowIds) {
27+
const response = await this.hubspot.getWorkflowDetails({
28+
workflowId,
29+
$,
30+
});
31+
workflows.push(response);
32+
}
33+
34+
$.export("$summary", `Successfully retrieved ${parsedWorkflowIds.length} workflows`);
35+
return {
36+
workflows,
37+
};
38+
},
39+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-retrieve-migrated-workflow-mappings",
5+
name: "Retrieve Migrated Workflow Mappings",
6+
description: "Retrieve mappings for migrated workflows. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
workflowId: {
12+
propDefinition: [
13+
hubspot,
14+
"workflowId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.hubspot.getMigratedWorkflowMappings({
20+
workflowId: this.workflowId,
21+
$,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved migrated workflow mappings for ${this.workflowId}`);
25+
return response;
26+
},
27+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-retrieve-workflow-details",
5+
name: "Retrieve Workflow Details",
6+
description: "Retrieve detailed information about a specific workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
workflowId: {
12+
propDefinition: [
13+
hubspot,
14+
"workflowId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.hubspot.getWorkflowDetails({
20+
workflowId: this.workflowId,
21+
$,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved details for workflow ${this.workflowId}`);
25+
return response;
26+
},
27+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-retrieve-workflow-emails",
5+
name: "Retrieve Workflow Emails",
6+
description: "Retrieve emails associated with a specific workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
workflowId: {
12+
propDefinition: [
13+
hubspot,
14+
"workflowId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.hubspot.getWorkflowEmails({
20+
workflowId: this.workflowId,
21+
$,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved emails for workflow ${this.workflowId}`);
25+
return response;
26+
},
27+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-retrieve-workflows",
5+
name: "Retrieve Workflows",
6+
description: "Retrieve a list of all workflows. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
},
12+
async run({ $ }) {
13+
const response = await this.hubspot.listWorkflows({
14+
$,
15+
});
16+
17+
$.export("$summary", `Successfully retrieved ${response.workflows.length} workflows`);
18+
return response;
19+
},
20+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
3+
export default {
4+
key: "hubspot-update-workflow",
5+
name: "Update a Workflow",
6+
description: "Update an existing workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/legacy/create-manage-workflows-v3/get-automation-v3-workflows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hubspot,
11+
workflowId: {
12+
propDefinition: [
13+
hubspot,
14+
"workflowId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Workflow Name",
20+
description: "The new name of the workflow",
21+
optional: true,
22+
},
23+
description: {
24+
type: "string",
25+
label: "Description",
26+
description: "The new description of the workflow",
27+
optional: true,
28+
},
29+
type: {
30+
type: "string",
31+
label: "Workflow Type",
32+
description: "The new type of workflow",
33+
optional: true,
34+
options: [
35+
{
36+
label: "DRIP",
37+
value: "DRIP",
38+
},
39+
{
40+
label: "SIMPLE",
41+
value: "SIMPLE",
42+
},
43+
{
44+
label: "COMPLEX",
45+
value: "COMPLEX",
46+
},
47+
],
48+
},
49+
triggerType: {
50+
type: "string",
51+
label: "Trigger Type",
52+
description: "The new trigger type for the workflow",
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
name, type, description, triggerType,
59+
} = this;
60+
61+
const updateData = {};
62+
if (name) updateData.name = name;
63+
if (description) updateData.description = description;
64+
if (type) updateData.type = type;
65+
if (triggerType) updateData.triggerType = triggerType;
66+
67+
const response = await this.hubspot.updateWorkflow({
68+
workflowId: this.workflowId,
69+
data: updateData,
70+
$,
71+
});
72+
73+
$.export("$summary", `Successfully updated workflow ${this.workflowId}`);
74+
return response;
75+
},
76+
};

components/hubspot/hubspot.app.mjs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,69 @@ export default {
12231223
...opts,
12241224
});
12251225
},
1226+
getWorkflowEmails({
1227+
workflowId, ...opts
1228+
}) {
1229+
return this.makeRequest({
1230+
api: API_PATH.AUTOMATIONV4,
1231+
endpoint: `/workflows/${workflowId}/emails`,
1232+
...opts,
1233+
});
1234+
},
1235+
getWorkflowDetails({
1236+
workflowId, ...opts
1237+
}) {
1238+
return this.makeRequest({
1239+
api: API_PATH.AUTOMATIONV4,
1240+
endpoint: `/workflows/${workflowId}`,
1241+
...opts,
1242+
});
1243+
},
1244+
createWorkflow(opts = {}) {
1245+
return this.makeRequest({
1246+
method: "POST",
1247+
api: API_PATH.AUTOMATIONV4,
1248+
endpoint: "/workflows",
1249+
...opts,
1250+
});
1251+
},
1252+
getBatchWorkflows(opts = {}) {
1253+
return this.makeRequest({
1254+
method: "POST",
1255+
api: API_PATH.AUTOMATIONV4,
1256+
endpoint: "/workflows/batch",
1257+
...opts,
1258+
});
1259+
},
1260+
updateWorkflow({
1261+
workflowId, ...opts
1262+
}) {
1263+
return this.makeRequest({
1264+
method: "PUT",
1265+
api: API_PATH.AUTOMATIONV4,
1266+
endpoint: `/workflows/${workflowId}`,
1267+
...opts,
1268+
});
1269+
},
1270+
deleteWorkflow({
1271+
workflowId, ...opts
1272+
}) {
1273+
return this.makeRequest({
1274+
method: "DELETE",
1275+
api: API_PATH.AUTOMATIONV4,
1276+
endpoint: `/workflows/${workflowId}`,
1277+
...opts,
1278+
});
1279+
},
1280+
getMigratedWorkflowMappings({
1281+
workflowId, ...opts
1282+
}) {
1283+
return this.makeRequest({
1284+
api: API_PATH.AUTOMATIONV4,
1285+
endpoint: `/workflows/${workflowId}/mappings`,
1286+
...opts,
1287+
});
1288+
},
12261289
batchCreateContacts(opts = {}) {
12271290
return this.makeRequest({
12281291
api: API_PATH.CRMV3,

0 commit comments

Comments
 (0)