-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Hubspot Improvements #12469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Hubspot Improvements #12469
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
803cb34
move common files
michelle0927 c8e2195
refactoring
michelle0927 0e0b6c0
create-associations - parse toObjectIds array
michelle0927 f0de627
bug fixes
michelle0927 08747b1
combine create-contact & create-or-update-contact
michelle0927 732fb87
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 dfec86e
versions
michelle0927 f3957a4
versions
michelle0927 521f3e5
new-contact & contact-updated -> new-or-updated-contact
michelle0927 b277b37
new-company & company-updated -> new-or-updated-company
michelle0927 67f979e
new-deal & new-deal-updated -> new-or-updated-deal
michelle0927 6317c47
ticket properties
michelle0927 a680dae
new-product & product-updated -> new-or-updated-product
michelle0927 552268f
new-line-item & line-item-updated -> new-or-updated-line-item
michelle0927 35e0a4c
new-blog-article & updated-blog-article -> new-or-updated-blog-article
michelle0927 99bb9b4
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 657d577
deprecate new-contact-in-list & add list filtering to new-or-updated-…
michelle0927 fde6b3d
filter engagements by type
michelle0927 70afd9d
add email event types
michelle0927 a213b9f
add test-event to new-email-event
michelle0927 e3f1775
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 896a144
add test-events to sources
michelle0927 024a0ad
add default props to create-deal
michelle0927 6ee9627
improve date prop descriptions
michelle0927 1e59e53
add default props to create-ticket
michelle0927 873d9cc
improve batch-create-or-update-contact
michelle0927 87e5987
add default properties to search-crm
michelle0927 03d0413
add createIfNotFound to search-crm
michelle0927 f9cfc85
add default props for get-company, get-contact, & get-deal
michelle0927 8060d57
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 99cc65f
refactoring
michelle0927 205b5aa
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 7e0d914
updates
michelle0927 b57a347
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 7f80305
improve summary
michelle0927 3a469b8
Merge remote-tracking branch 'origin/master' into hubspot-updates
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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[]", | ||
| }, | ||
| }, | ||
|
|
@@ -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({ | ||
| $, | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
components/hubspot/actions/common/common-get-object.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 []; | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| 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; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.