Skip to content

Commit 3e72137

Browse files
committed
update create-associations
1 parent 8e8ce01 commit 3e72137

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

components/hubspot/actions/create-associations/create-associations.mjs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import hubspot from "../../hubspot.app.mjs";
2-
import { ASSOCIATION_CATEGORY } from "../../common/constants.mjs";
32
import { ConfigurationError } from "@pipedream/platform";
43

54
export default {
65
key: "hubspot-create-associations",
76
name: "Create Associations",
87
description: "Create associations between objects. [See the documentation](https://developers.hubspot.com/docs/api/crm/associations#endpoint?spec=POST-/crm/v3/associations/{fromObjectType}/{toObjectType}/batch/create)",
9-
version: "0.0.9",
8+
version: "0.0.10",
109
type: "action",
1110
props: {
1211
hubspot,
1312
fromObjectType: {
1413
propDefinition: [
1514
hubspot,
1615
"objectType",
16+
() => ({
17+
includeCustom: true,
18+
}),
1719
],
1820
label: "From Object Type",
1921
description: "The type of the object being associated",
@@ -34,6 +36,9 @@ export default {
3436
propDefinition: [
3537
hubspot,
3638
"objectType",
39+
() => ({
40+
includeCustom: true,
41+
}),
3742
],
3843
label: "To Object Type",
3944
description: "Type of the objects the from object is being associated with",
@@ -60,6 +65,20 @@ export default {
6065
description: "Id's of the objects the from object is being associated with",
6166
},
6267
},
68+
methods: {
69+
async getAssociationCategory({
70+
$, fromObjectType, toObjectType, associationType,
71+
}) {
72+
const { results } = await this.hubspot.getAssociationTypes({
73+
$,
74+
fromObjectType,
75+
toObjectType,
76+
associationType,
77+
});
78+
const association = results.find(({ typeId }) => typeId === this.associationType);
79+
return association.category;
80+
},
81+
},
6382
async run({ $ }) {
6483
const {
6584
fromObjectType,
@@ -77,6 +96,13 @@ export default {
7796
throw new ConfigurationError("Could not parse \"To Objects\" array.");
7897
}
7998
}
99+
100+
const associationCategory = await this.getAssociationCategory({
101+
$,
102+
fromObjectType,
103+
toObjectType,
104+
associationType,
105+
});
80106
const response = await this.hubspot.createAssociations({
81107
$,
82108
fromObjectType,
@@ -91,7 +117,7 @@ export default {
91117
},
92118
types: [
93119
{
94-
associationCategory: ASSOCIATION_CATEGORY.HUBSPOT_DEFINED,
120+
associationCategory,
95121
associationTypeId: associationType,
96122
},
97123
],

components/hubspot/hubspot.app.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,19 @@ export default {
7777
type: "string",
7878
label: "Object Type",
7979
description: "Watch for new events concerning the object type specified.",
80-
async options() {
81-
return OBJECT_TYPES;
80+
async options({ includeCustom = false }) {
81+
const objectTypes = OBJECT_TYPES;
82+
if (includeCustom) {
83+
const { results } = await this.listSchemas();
84+
const customObjects = results?.map(({
85+
name: value, labels,
86+
}) => ({
87+
value,
88+
label: labels.plural,
89+
})) || [];
90+
objectTypes.push(...customObjects);
91+
}
92+
return objectTypes;
8293
},
8394
},
8495
objectSchema: {

0 commit comments

Comments
 (0)