Skip to content

Commit 694d552

Browse files
committed
Update HubSpot Workflow Management Actions
- Refactored workflow-related actions to align with the v4 API, including: - Updated endpoints and request structures for creating, retrieving, updating, and deleting workflows. - Added new properties for workflow creation and management, such as `isEnabled`, `actions`, and `enrollmentCriteria`. - Enhanced error handling and response parsing for better integration. - Bumped package version to 1.7.0 to reflect these changes.
1 parent 9620829 commit 694d552

File tree

9 files changed

+219
-131
lines changed

9 files changed

+219
-131
lines changed
Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import hubspot from "../../hubspot.app.mjs";
23

34
export default {
45
key: "hubspot-create-workflow",
56
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",
7+
description: "Create a new workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/post-automation-v4-flows)",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
hubspot,
@@ -13,60 +14,46 @@ export default {
1314
label: "Workflow Name",
1415
description: "The name of the workflow to create",
1516
},
17+
isEnabled: {
18+
propDefinition: [
19+
hubspot,
20+
"isEnabled",
21+
],
22+
},
1623
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-
},
24+
propDefinition: [
25+
hubspot,
26+
"type",
3327
],
3428
},
35-
description: {
36-
type: "string",
37-
label: "Description",
38-
description: "Description of the workflow",
39-
optional: true,
29+
actions: {
30+
propDefinition: [
31+
hubspot,
32+
"actions",
33+
],
4034
},
41-
triggerType: {
42-
type: "string",
43-
label: "Trigger Type",
44-
description: "The type of trigger for the workflow",
45-
optional: true,
35+
enrollmentCriteria: {
36+
propDefinition: [
37+
hubspot,
38+
"enrollmentCriteria",
39+
],
4640
},
4741
},
4842
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-
6443
const response = await this.hubspot.createWorkflow({
65-
data: workflowData,
44+
data: {
45+
name: this.name,
46+
type: this.type,
47+
isEnabled: this.isEnabled,
48+
objectTypeId: "0-1",
49+
flowType: "WORKFLOW",
50+
actions: parseObject(this.actions),
51+
enrollmentCriteria: parseObject(this.enrollmentCriteria),
52+
},
6653
$,
6754
});
6855

69-
$.export("$summary", `Successfully created workflow: ${name}`);
56+
$.export("$summary", `Successfully created workflow: ${this.name}`);
7057
return response;
7158
},
7259
};

components/hubspot/actions/delete-workflow/delete-workflow.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import hubspot from "../../hubspot.app.mjs";
33
export default {
44
key: "hubspot-delete-workflow",
55
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",
6+
description: "Delete a workflow by ID. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/delete-automation-v4-flows-flowId)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
hubspot,
1111
workflowId: {
12-
type: "string",
13-
label: "Workflow ID",
12+
propDefinition: [
13+
hubspot,
14+
"workflow",
15+
],
1416
description: "The ID of the workflow to delete",
1517
},
1618
},
1719
async run({ $ }) {
18-
const { workflowId } = this;
19-
2020
const response = await this.hubspot.deleteWorkflow({
21-
workflowId,
21+
workflowId: this.workflowId,
2222
$,
2323
});
2424

25-
$.export("$summary", `Successfully deleted workflow ${workflowId}`);
25+
$.export("$summary", `Successfully deleted workflow ${this.workflowId}`);
2626
return response;
2727
},
2828
};
Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import hubspot from "../../hubspot.app.mjs";
23

34
export default {
45
key: "hubspot-retrieve-migrated-workflow-mappings",
56
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+
description: "Retrieve the IDs of v3 workflows that have been migrated to the v4 API. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflow-id-mappings/post-automation-v4-workflow-id-mappings-batch-read)",
78
version: "0.0.1",
89
type: "action",
910
props: {
1011
hubspot,
11-
workflowId: {
12-
propDefinition: [
13-
hubspot,
14-
"workflowId",
15-
],
12+
flowIds: {
13+
type: "string[]",
14+
label: "Flow IDs",
15+
description: "A list of flowIds from the V4 API.",
16+
optional: true,
17+
},
18+
workflowIds: {
19+
type: "string[]",
20+
label: "Workflow IDs",
21+
description: "A list of workflowIds from the V3 API.",
22+
optional: true,
1623
},
1724
},
1825
async run({ $ }) {
26+
const parsedFlowIds = parseObject(this.flowIds) || [];
27+
const parsedWorkflowIds = parseObject(this.workflowIds) || [];
28+
29+
const flowIds = [];
30+
const workflowIds = [];
31+
32+
for (const flowId of parsedFlowIds) {
33+
flowIds.push({
34+
flowMigrationStatuses: `${flowId}`,
35+
type: "FLOW_ID",
36+
});
37+
}
38+
for (const workflowId of parsedWorkflowIds) {
39+
workflowIds.push({
40+
flowMigrationStatusForClassicWorkflows: `${workflowId}`,
41+
type: "WORKFLOW_ID",
42+
});
43+
}
44+
1945
const response = await this.hubspot.getMigratedWorkflowMappings({
20-
workflowId: this.workflowId,
2146
$,
47+
data: {
48+
inputs: [
49+
...flowIds,
50+
...workflowIds,
51+
],
52+
},
2253
});
2354

24-
$.export("$summary", `Successfully retrieved migrated workflow mappings for ${this.workflowId}`);
55+
$.export("$summary", `Successfully retrieved ${response.results.length} migrated result(s) with ${response.errors?.length || 0} error(s)`);
2556
return response;
2657
},
2758
};

components/hubspot/actions/retrieve-workflow-details/retrieve-workflow-details.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import hubspot from "../../hubspot.app.mjs";
33
export default {
44
key: "hubspot-retrieve-workflow-details",
55
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)",
6+
description: "Retrieve detailed information about a specific workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/get-automation-v4-flows-flowId)",
77
version: "0.0.1",
88
type: "action",
99
props: {
1010
hubspot,
1111
workflowId: {
1212
propDefinition: [
1313
hubspot,
14-
"workflowId",
14+
"workflow",
1515
],
16+
label: "Workflow ID",
17+
description: "The ID of the workflow you wish to see details for.",
1618
},
1719
},
1820
async run({ $ }) {

components/hubspot/actions/retrieve-workflow-emails/retrieve-workflow-emails.mjs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,49 @@ import hubspot from "../../hubspot.app.mjs";
33
export default {
44
key: "hubspot-retrieve-workflow-emails",
55
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)",
6+
description: "Retrieve emails sent by a workflow by ID. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/email-campaigns/get-automation-v4-flows-email-campaigns)",
77
version: "0.0.1",
88
type: "action",
99
props: {
1010
hubspot,
1111
workflowId: {
1212
propDefinition: [
1313
hubspot,
14-
"workflowId",
14+
"workflow",
1515
],
1616
},
17+
after: {
18+
type: "string",
19+
label: "After",
20+
description: "The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results.",
21+
optional: true,
22+
},
23+
before: {
24+
type: "string",
25+
label: "Before",
26+
description: "The paging cursor token of the last successfully read resource will be returned as the `paging.next.before` JSON property of a paged response containing more results.",
27+
optional: true,
28+
},
29+
limit: {
30+
type: "integer",
31+
label: "Limit",
32+
description: "The maximum number of results to display per page.",
33+
default: 100,
34+
optional: true,
35+
},
1736
},
1837
async run({ $ }) {
1938
const response = await this.hubspot.getWorkflowEmails({
20-
workflowId: this.workflowId,
2139
$,
40+
params: {
41+
flowId: this.workflowId,
42+
after: this.after,
43+
before: this.before,
44+
limit: this.limit,
45+
},
2246
});
2347

24-
$.export("$summary", `Successfully retrieved emails for workflow ${this.workflowId}`);
48+
$.export("$summary", `Successfully retrieved ${response.results.length} emails for workflow ${this.workflowId}`);
2549
return response;
2650
},
2751
};

components/hubspot/actions/retrieve-workflows/retrieve-workflows.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,35 @@ import hubspot from "../../hubspot.app.mjs";
33
export default {
44
key: "hubspot-retrieve-workflows",
55
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)",
6+
description: "Retrieve a list of all workflows. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/get-automation-v4-flows)",
77
version: "0.0.1",
88
type: "action",
99
props: {
1010
hubspot,
11+
after: {
12+
type: "string",
13+
label: "After",
14+
description: "The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results.",
15+
optional: true,
16+
},
17+
limit: {
18+
type: "integer",
19+
label: "Limit",
20+
description: "The maximum number of results to display per page.",
21+
default: 100,
22+
optional: true,
23+
},
1124
},
1225
async run({ $ }) {
1326
const response = await this.hubspot.listWorkflows({
1427
$,
28+
params: {
29+
after: this.after,
30+
limit: this.limit,
31+
},
1532
});
1633

17-
$.export("$summary", `Successfully retrieved ${response.workflows.length} workflows`);
34+
$.export("$summary", `Successfully retrieved ${response.results.length} workflows`);
1835
return response;
1936
},
2037
};

0 commit comments

Comments
 (0)