Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions components/hubspot/actions/create-workflow/create-workflow.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { parseObject } from "../../common/utils.mjs";
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-create-workflow",
name: "Create a New Workflow",
description: "Create a new workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/post-automation-v4-flows)",
version: "0.0.1",
type: "action",
props: {
hubspot,
name: {
type: "string",
label: "Workflow Name",
description: "The name of the workflow to create",
},
isEnabled: {
propDefinition: [
hubspot,
"isEnabled",
],
},
type: {
propDefinition: [
hubspot,
"type",
],
},
actions: {
propDefinition: [
hubspot,
"actions",
],
},
enrollmentCriteria: {
propDefinition: [
hubspot,
"enrollmentCriteria",
],
},
},
async run({ $ }) {
const response = await this.hubspot.createWorkflow({
data: {
name: this.name,
type: this.type,
isEnabled: this.isEnabled,
objectTypeId: "0-1",
flowType: "WORKFLOW",
actions: parseObject(this.actions),
enrollmentCriteria: parseObject(this.enrollmentCriteria),
},
$,
});

$.export("$summary", `Successfully created workflow: ${this.name}`);
return response;
},
};
28 changes: 28 additions & 0 deletions components/hubspot/actions/delete-workflow/delete-workflow.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-delete-workflow",
name: "Delete a Workflow",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
workflowId: {
propDefinition: [
hubspot,
"workflow",
],
description: "The ID of the workflow to delete",
},
},
async run({ $ }) {
const response = await this.hubspot.deleteWorkflow({
workflowId: this.workflowId,
$,
});

$.export("$summary", `Successfully deleted workflow ${this.workflowId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { parseObject } from "../../common/utils.mjs";
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-retrieve-batch-workflows",
name: "Retrieve a Batch of Workflows",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
workflowIds: {
propDefinition: [
hubspot,
"workflowId",
],
type: "string[]",
label: "Workflow IDs",
description: "A list of workflow IDs to retrieve",
},
},
async run({ $ }) {
const workflows = [];
const parsedWorkflowIds = parseObject(this.workflowIds);

for (const workflowId of parsedWorkflowIds) {
const response = await this.hubspot.getWorkflowDetails({
workflowId,
$,
});
workflows.push(response);
}

$.export("$summary", `Successfully retrieved ${parsedWorkflowIds.length} workflows`);
return {
workflows,
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { parseObject } from "../../common/utils.mjs";
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-retrieve-migrated-workflow-mappings",
name: "Retrieve Migrated Workflow Mappings",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
flowIds: {
type: "string[]",
label: "Flow IDs",
description: "A list of flowIds from the V4 API.",
optional: true,
},
workflowIds: {
type: "string[]",
label: "Workflow IDs",
description: "A list of workflowIds from the V3 API.",
optional: true,
},
},
async run({ $ }) {
const parsedFlowIds = parseObject(this.flowIds) || [];
const parsedWorkflowIds = parseObject(this.workflowIds) || [];

const flowIds = [];
const workflowIds = [];

for (const flowId of parsedFlowIds) {
flowIds.push({
flowMigrationStatuses: `${flowId}`,
type: "FLOW_ID",
});
}
for (const workflowId of parsedWorkflowIds) {
workflowIds.push({
flowMigrationStatusForClassicWorkflows: `${workflowId}`,
type: "WORKFLOW_ID",
});
}

const response = await this.hubspot.getMigratedWorkflowMappings({
$,
data: {
inputs: [
...flowIds,
...workflowIds,
],
},
});

$.export("$summary", `Successfully retrieved ${response.results.length} migrated result(s) with ${response.errors?.length || 0} error(s)`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-retrieve-workflow-details",
name: "Retrieve Workflow Details",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
workflowId: {
propDefinition: [
hubspot,
"workflow",
],
label: "Workflow ID",
description: "The ID of the workflow you wish to see details for.",
},
},
async run({ $ }) {
const response = await this.hubspot.getWorkflowDetails({
workflowId: this.workflowId,
$,
});

$.export("$summary", `Successfully retrieved details for workflow ${this.workflowId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-retrieve-workflow-emails",
name: "Retrieve Workflow Emails",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
workflowId: {
propDefinition: [
hubspot,
"workflow",
],
},
after: {
type: "string",
label: "After",
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.",
optional: true,
},
before: {
type: "string",
label: "Before",
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.",
optional: true,
},
limit: {
type: "integer",
label: "Limit",
description: "The maximum number of results to display per page.",
default: 100,
optional: true,
},
},
async run({ $ }) {
const response = await this.hubspot.getWorkflowEmails({
$,
params: {
flowId: this.workflowId,
after: this.after,
before: this.before,
limit: this.limit,
},
});

$.export("$summary", `Successfully retrieved ${response.results.length} emails for workflow ${this.workflowId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-retrieve-workflows",
name: "Retrieve Workflows",
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)",
version: "0.0.1",
type: "action",
props: {
hubspot,
after: {
type: "string",
label: "After",
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.",
optional: true,
},
limit: {
type: "integer",
label: "Limit",
description: "The maximum number of results to display per page.",
default: 100,
optional: true,
},
},
async run({ $ }) {
const response = await this.hubspot.listWorkflows({
$,
params: {
after: this.after,
limit: this.limit,
},
});

$.export("$summary", `Successfully retrieved ${response.results.length} workflows`);
return response;
},
};
82 changes: 82 additions & 0 deletions components/hubspot/actions/update-workflow/update-workflow.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { parseObject } from "../../common/utils.mjs";
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-update-workflow",
name: "Update a Workflow",
description: "Update an existing workflow. [See the documentation](https://developers.hubspot.com/docs/api-reference/automation-automation-v4-v4/workflows/put-automation-v4-flows-flowId)",
version: "0.0.1",
type: "action",
props: {
hubspot,
workflowId: {
propDefinition: [
hubspot,
"workflow",
],
description: "The ID of the workflow to update",
},
name: {
type: "string",
label: "Workflow Name",
description: "The new name of the workflow",
optional: true,
},
type: {
propDefinition: [
hubspot,
"type",
],
},
isEnabled: {
propDefinition: [
hubspot,
"isEnabled",
],
},
actions: {
propDefinition: [
hubspot,
"actions",
],
},
enrollmentCriteria: {
propDefinition: [
hubspot,
"enrollmentCriteria",
],
},
revisionId: {
type: "string",
label: "Revision ID",
description: "The revision ID of the workflow",
optional: true,
},
},
async run({ $ }) {
const data = {};

if (this.name) data.name = this.name;
if (this.type) data.type = this.type;
if (Object.hasOwn(this, "isEnabled")) data.isEnabled = this.isEnabled;
if (this.actions) data.actions = parseObject(this.actions);
if (this.enrollmentCriteria) data.enrollmentCriteria = parseObject(this.enrollmentCriteria);
if (!this.revisionId) {
const workflow = await this.hubspot.getWorkflowDetails({
workflowId: this.workflowId,
});
data.revisionId = workflow.revisionId + 1;
} else {
data.revisionId = this.revisionId;
}

const response = await this.hubspot.updateWorkflow({
workflowId: this.workflowId,
data,
$,
});

$.export("$summary", `Successfully updated workflow ${this.workflowId}`);
return response;
},
};
Loading
Loading