Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
803cb34
move common files
michelle0927 Jun 14, 2024
c8e2195
refactoring
michelle0927 Jun 17, 2024
0e0b6c0
create-associations - parse toObjectIds array
michelle0927 Jun 17, 2024
f0de627
bug fixes
michelle0927 Jun 17, 2024
08747b1
combine create-contact & create-or-update-contact
michelle0927 Jun 18, 2024
732fb87
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 18, 2024
dfec86e
versions
michelle0927 Jun 18, 2024
f3957a4
versions
michelle0927 Jun 18, 2024
521f3e5
new-contact & contact-updated -> new-or-updated-contact
michelle0927 Jun 20, 2024
b277b37
new-company & company-updated -> new-or-updated-company
michelle0927 Jun 20, 2024
67f979e
new-deal & new-deal-updated -> new-or-updated-deal
michelle0927 Jun 20, 2024
6317c47
ticket properties
michelle0927 Jun 20, 2024
a680dae
new-product & product-updated -> new-or-updated-product
michelle0927 Jun 20, 2024
552268f
new-line-item & line-item-updated -> new-or-updated-line-item
michelle0927 Jun 20, 2024
35e0a4c
new-blog-article & updated-blog-article -> new-or-updated-blog-article
michelle0927 Jun 20, 2024
99bb9b4
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 20, 2024
657d577
deprecate new-contact-in-list & add list filtering to new-or-updated-…
michelle0927 Jun 21, 2024
fde6b3d
filter engagements by type
michelle0927 Jun 21, 2024
70afd9d
add email event types
michelle0927 Jun 21, 2024
a213b9f
add test-event to new-email-event
michelle0927 Jun 21, 2024
e3f1775
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 21, 2024
896a144
add test-events to sources
michelle0927 Jun 24, 2024
024a0ad
add default props to create-deal
michelle0927 Jun 25, 2024
6ee9627
improve date prop descriptions
michelle0927 Jun 25, 2024
1e59e53
add default props to create-ticket
michelle0927 Jun 25, 2024
873d9cc
improve batch-create-or-update-contact
michelle0927 Jun 25, 2024
87e5987
add default properties to search-crm
michelle0927 Jun 25, 2024
03d0413
add createIfNotFound to search-crm
michelle0927 Jun 25, 2024
f9cfc85
add default props for get-company, get-contact, & get-deal
michelle0927 Jun 25, 2024
8060d57
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 25, 2024
99cc65f
refactoring
michelle0927 Jun 26, 2024
205b5aa
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 26, 2024
7e0d914
updates
michelle0927 Jun 27, 2024
b57a347
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 27, 2024
7f80305
improve summary
michelle0927 Jun 28, 2024
3a469b8
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 Jun 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "hubspot-add-contact-to-list",
name: "Add Contact to List",
description: "Adds a contact to a specific static list. [See the documentation](https://legacydocs.hubspot.com/docs/methods/lists/add_contact_to_list)",
version: "0.0.8",
version: "0.0.9",
type: "action",
props: {
hubspot,
Expand Down Expand Up @@ -33,9 +33,15 @@ export default {
list,
contactEmail,
} = this;
const response = await this.hubspot.addContactsToList(list.value, [
contactEmail,
], $);
const response = await this.hubspot.addContactsToList({
$,
listId: list.value,
data: {
emails: [
contactEmail,
],
},
});
$.export("$summary", "Successfully added contact to list");
return response;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import hubspot from "../../hubspot.app.mjs";
export default {
key: "hubspot-batch-create-or-update-contact",
name: "Batch Create or Update Contact",
description: "Create or update a batch of contacts by its ID. [See the documentation](https://developers.hubspot.com/docs/api/crm/contacts)",
version: "0.0.5",
description: "Create or update a batch of contacts by its ID or email. [See the documentation](https://developers.hubspot.com/docs/api/crm/contacts)",
version: "0.0.6",
type: "action",
props: {
hubspot,
contacts: {
label: "Contacts Array",
description: "Provide a **list of contacts** to be created or updated. If the provided contact has the prop ID, this action will attempt to update it.\n\n**Expected format for create:** `{ \"company\": \"Biglytics\", \"email\": \"[email protected]\", \"firstname\": \"Bryan\", \"lastname\": \"Cooper\", \"phone\": \"(877) 929-0687\", \"website\": \"biglytics.net\" }` \n\n**Expected format for update:** `{ \"id\": \"101\", \"company\": \"Biglytics\", \"email\": \"[email protected]\", \"firstname\": \"Bryan\", \"lastname\": \"Cooper\", \"phone\": \"(877) 929-0687\", \"website\": \"biglytics.net\" }`",
description: "Provide a **list of contacts** to be created or updated. If the provided contact has the prop ID or if the provided email already exists, this action will attempt to update it.\n\n**Expected format for create:** `{ \"company\": \"Biglytics\", \"email\": \"[email protected]\", \"firstname\": \"Bryan\", \"lastname\": \"Cooper\", \"phone\": \"(877) 929-0687\", \"website\": \"biglytics.net\" }` \n\n**Expected format for update:** `{ \"id\": \"101\", \"company\": \"Biglytics\", \"email\": \"[email protected]\", \"firstname\": \"Bryan\", \"lastname\": \"Cooper\", \"phone\": \"(877) 929-0687\", \"website\": \"biglytics.net\" }`",
type: "string[]",
},
},
Expand All @@ -24,23 +24,58 @@ export default {
}
return contacts;
},
async searchExistingContactProperties(contacts, $) {
const emails = contacts.map(({ email }) => email);
const { results } = await this.hubspot.searchCRM({
$,
object: "contact",
data: {
filters: [
{
propertyName: "email",
operator: "IN",
values: emails,
},
],
},
});
const updateEmails = results?.map(({ properties }) => properties.email);
const insertProperties = contacts.filter(({ email }) => !updateEmails.includes(email))
.map((properties) => ({
properties,
}));
const updateProperties = [];
for (const contact of results) {
updateProperties.push({
id: contact.id,
properties: contacts.find(({ email }) => contact.properties.email === email),
});
}
return {
insertProperties,
updateProperties,
};
},
},
async run({ $ }) {
const contacts = this.parseContactArray(this.contacts);

const insertProperties = contacts.filter((contact) => (!Object.prototype.hasOwnProperty.call(contact, "id")))
.map((properties) => ({
properties,
}));
const {
insertProperties, updateProperties,
} = await this.searchExistingContactProperties(contacts, $);

const updateProperties = contacts.filter((contact) => (Object.prototype.hasOwnProperty.call(contact, "id")))
const updatePropertiesWithId = contacts.filter((contact) => (Object.prototype.hasOwnProperty.call(contact, "id")))
.map(({
id, ...properties
}) => ({
id: id,
properties,
}));

if (updatePropertiesWithId?.length) {
updateProperties.push(...updatePropertiesWithId);
}

let response = {};
response.created = await this.hubspot.batchCreateContacts({
$,
Expand Down
51 changes: 0 additions & 51 deletions components/hubspot/actions/common-get-object.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default {
label: "Property Groups",
reloadProps: true,
async options() {
const { results: groups } = await this.hubspot.getPropertyGroups(this.getObjectType());
const { results: groups } = await this.hubspot.getPropertyGroups({
objectType: this.getObjectType(),
});
return groups.map((group) => ({
label: group.label,
value: group.name,
Expand All @@ -23,7 +25,13 @@ export default {
...common.methods,
isRelevantProperty(property) {
const isInPropertyGroups = this.propertyGroups?.includes(property.groupName);
return common.methods.isRelevantProperty(property) && isInPropertyGroups;
const isDefaultProperty = this.isDefaultProperty(property);
return common.methods.isRelevantProperty(property)
&& isInPropertyGroups
&& !isDefaultProperty;
},
isDefaultProperty() {
return false;
},
},
async run({ $ }) {
Expand All @@ -46,7 +54,13 @@ export default {
}
});
try {
const response = await hubspot.createObject(objectType, properties, $);
const response = await hubspot.createObject({
$,
objectType,
data: {
properties,
},
});
const objectName = hubspot.getObjectTypeName(objectType);
$.export("$summary", `Successfully created ${objectName}`);

Expand All @@ -56,7 +70,14 @@ export default {
const errorObj = JSON.parse(err?.message);
if (errorObj?.category === "CONFLICT" || errorObj?.category === "OBJECT_ALREADY_EXISTS") {
const objectId = parseInt(errorObj.message.replace(/[^\d]/g, ""));
const response = await hubspot.updateObject(objectType, properties, objectId, $);
const response = await hubspot.updateObject({
$,
objectType,
objectId,
data: {
properties,
},
});
const objectName = hubspot.getObjectTypeName(objectType);
$.export("$summary", `Successfully updated ${objectName}`);
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hubspot from "../hubspot.app.mjs";
import hubspot from "../../hubspot.app.mjs";
import {
OBJECT_TYPE, HUBSPOT_OWNER,
} from "../common/constants.mjs";
} from "../../common/constants.mjs";

/**
* Returns an options method for a CRM object type, intended to be used in
Expand Down Expand Up @@ -83,19 +83,28 @@ export default {
type = "string[]";
}

if (property.name === "hs_timestamp") {
property.description += ". Enter date in ISO-8601 format. Example: `2024-06-25T15:43:49.214Z`";
}

return {
type,
name: property.name,
label: property.label,
description: property.description,
optional: !requiredProperties.includes(property),
optional: !requiredProperties.includes(property.name),
options,
};
},
},
async additionalProps() {
const schema = await this.hubspot.getSchema(this.getObjectType());
const { results: properties } = await this.hubspot.getProperties(this.getObjectType());
const objectType = this.getObjectType();
const schema = await this.hubspot.getSchema({
objectType,
});
const { results: properties } = await this.hubspot.getProperties({
objectType,
});
return properties
.filter(this.isRelevantProperty)
.map((property) => this.makePropDefinition(property, schema.requiredProperties))
Expand Down
102 changes: 102 additions & 0 deletions components/hubspot/actions/common/common-get-object.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import hubspot from "../../hubspot.app.mjs";
import {
DEFAULT_CONTACT_PROPERTIES,
DEFAULT_COMPANY_PROPERTIES,
DEFAULT_DEAL_PROPERTIES,
DEFAULT_TICKET_PROPERTIES,
DEFAULT_PRODUCT_PROPERTIES,
DEFAULT_LINE_ITEM_PROPERTIES,
} from "../../common/constants.mjs";

export default {
props: {
hubspot,
objectId: {
type: "string",
label: "Object ID",
description: "Hubspot's internal ID for the object",
async options(opts) {
return this.hubspot.createOptions(this.getObjectType(), opts);
},
reloadProps: true,
},
info: {
type: "alert",
alertType: "info",
content: "",
hidden: true,
},
// eslint-disable-next-line pipedream/props-description
additionalProperties: {
type: "string[]",
label: "Additional properties to retrieve",
optional: true,
async options({ page }) {
if (page !== 0) {
return [];
}
const { results: properties } = await this.hubspot.getProperties({
objectType: this.getObjectType(),
});
const defaultProperties = this.getDefaultProperties(this.getObjectType());
return properties
.filter(({ name }) => !defaultProperties.includes(name))
.map((property) => ({
label: property.label,
value: property.name,
}));
},
},
},
async additionalProps(props) {
return {
info: {
...props.info,
content: `Properties:\n\`${this.getDefaultProperties(this.getObjectType()).join(", ")}\``,
hidden: false,
},
};
},
methods: {
getObjectType() {
throw new Error("getObjectType is not implemented");
},
getDefaultProperties(objectType) {
if (objectType === "contact") {
return DEFAULT_CONTACT_PROPERTIES;
} else if (objectType === "company") {
return DEFAULT_COMPANY_PROPERTIES;
} else if (objectType === "deal") {
return DEFAULT_DEAL_PROPERTIES;
} else if (objectType === "ticket") {
return DEFAULT_TICKET_PROPERTIES;
} else if (objectType === "product") {
return DEFAULT_PRODUCT_PROPERTIES;
} else if (objectType === "line_item") {
return DEFAULT_LINE_ITEM_PROPERTIES;
} else {
return [];
}
},
},
async run({ $ }) {
const objectType = this.getObjectType();
const { additionalProperties = [] } = this;
const defaultProperties = this.getDefaultProperties(this.getObjectType());

const object = await this.hubspot.getObject(
objectType,
this.objectId,
[
...defaultProperties,
...additionalProperties,
],
$,
);

const objectName = this.hubspot.getObjectTypeName(objectType);
$.export("$summary", `Successfully fetched ${objectName}`);

return object;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default {
label: "Property Groups",
reloadProps: true,
async options() {
const { results: groups } = await this.hubspot.getPropertyGroups(this.getObjectType());
const { results: groups } = await this.hubspot.getPropertyGroups({
objectType: this.getObjectType(),
});
return groups.map((group) => ({
label: group.label,
value: group.name,
Expand Down Expand Up @@ -45,7 +47,13 @@ export default {
}
});

const response = await hubspot.updateObject(objectType, properties, objectId, $);
const response = await hubspot.updateObject({
objectType,
objectId,
data: {
properties,
},
});
const objectName = hubspot.getObjectTypeName(objectType);

$.export("$summary", `Successfully updated ${objectName}`);
Expand Down
Loading