Skip to content

Commit 6081aab

Browse files
committed
create-note action
1 parent 28e91bb commit 6081aab

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import common from "../common/common-create.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import { ASSOCIATION_CATEGORY } from "../../common/constants.mjs";
4+
5+
export default {
6+
...common,
7+
key: "hubspot-create-note",
8+
name: "Create Note",
9+
description: "Create a new note. [See the documentation](https://developers.hubspot.com/docs/api/crm/engagements)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
...common.props,
14+
toObjectType: {
15+
propDefinition: [
16+
common.props.hubspot,
17+
"objectType",
18+
],
19+
label: "Associated Object Type",
20+
description: "Type of object the note is being associated with",
21+
optional: true,
22+
},
23+
toObjectId: {
24+
propDefinition: [
25+
common.props.hubspot,
26+
"objectId",
27+
(c) => ({
28+
objectType: c.toObjectType,
29+
}),
30+
],
31+
label: "Associated Object",
32+
description: "ID of object the note is being associated with",
33+
optional: true,
34+
},
35+
associationType: {
36+
propDefinition: [
37+
common.props.hubspot,
38+
"associationType",
39+
(c) => ({
40+
fromObjectType: "notes",
41+
toObjectType: c.toObjectType,
42+
}),
43+
],
44+
description: "A unique identifier to indicate the association type between the note and the other object",
45+
optional: true,
46+
},
47+
},
48+
methods: {
49+
...common.methods,
50+
getObjectType() {
51+
return "notes";
52+
},
53+
isRelevantProperty(property) {
54+
return common.methods.isRelevantProperty(property) && !property.name.includes("hs_pipeline");
55+
},
56+
createEngagement(objectType, properties, associations, $) {
57+
return this.hubspot.createObject({
58+
objectType,
59+
data: {
60+
properties,
61+
associations,
62+
},
63+
$,
64+
});
65+
},
66+
},
67+
async run({ $ }) {
68+
const {
69+
hubspot,
70+
/* eslint-disable no-unused-vars */
71+
toObjectType,
72+
toObjectId,
73+
associationType,
74+
$db,
75+
objectProperties,
76+
...otherProperties
77+
} = this;
78+
79+
if ((toObjectId && !associationType) || (!toObjectId && associationType)) {
80+
throw new ConfigurationError("Both `toObjectId` and `associationType` must be entered");
81+
}
82+
83+
const properties = objectProperties
84+
? typeof objectProperties === "string"
85+
? JSON.parse(objectProperties)
86+
: objectProperties
87+
: otherProperties;
88+
89+
const objectType = this.getObjectType();
90+
91+
const associations = toObjectId
92+
? [
93+
{
94+
to: {
95+
id: toObjectId,
96+
},
97+
types: [
98+
{
99+
associationTypeId: associationType,
100+
associationCategory: ASSOCIATION_CATEGORY.HUBSPOT_DEFINED,
101+
},
102+
],
103+
},
104+
]
105+
: undefined;
106+
107+
if (properties.hs_task_reminders) {
108+
properties.hs_task_reminders = Date.parse(properties.hs_task_reminders);
109+
}
110+
111+
const engagement = await this.createEngagement(objectType, properties, associations, $);
112+
113+
const objectName = hubspot.getObjectTypeName(objectType);
114+
$.export("$summary", `Successfully created ${objectName}`);
115+
116+
return engagement;
117+
},
118+
};

components/hubspot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/hubspot",
3-
"version": "1.2.4",
3+
"version": "1.3.0",
44
"description": "Pipedream Hubspot Components",
55
"main": "hubspot.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)