From 0c6f36dc553ae956bbfa5cacaea10ed29631a338 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 20 Aug 2025 23:36:20 -0300 Subject: [PATCH 1/6] 'Get Associated Emails' action --- .../get-associated-emails.mjs | 109 ++++++++++++++++++ components/hubspot/common/constants.mjs | 12 ++ 2 files changed, 121 insertions(+) create mode 100644 components/hubspot/actions/get-associated-emails/get-associated-emails.mjs diff --git a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs new file mode 100644 index 0000000000000..550e7681a3cb5 --- /dev/null +++ b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs @@ -0,0 +1,109 @@ +import { + DEFAULT_EMAIL_PROPERTIES, OBJECT_TYPE, OBJECT_TYPES, +} from "../../common/constants.mjs"; +import hubspot from "../../hubspot.app.mjs"; + +export default { + key: "hubspot-get-associated-emails", + name: "Get Associated Emails", + description: "Retrieves emails associated with a specific object (contact, company, or deal). [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/search)", + version: "0.0.1", + type: "action", + props: { + hubspot, + objectType: { + type: "string", + label: "Associated Object Type", + description: "The type of the object the emails are associated with", + options: OBJECT_TYPES.filter(({ value }) => [ + OBJECT_TYPE.CONTACT, + OBJECT_TYPE.COMPANY, + OBJECT_TYPE.DEAL, + ].includes(value)), + }, + objectId: { + type: "string", + label: "Object ID", + description: "The ID of the object to get associated emails for", + propDefinition: [ + hubspot, + "objectIds", + ({ objectType }) => ({ + objectType, + }), + ], + }, + additionalProperties: { + type: "string[]", + label: "Additional Properties", + description: "Additional properties to retrieve for the emails", + optional: true, + }, + limit: { + type: "integer", + label: "Limit", + description: "Maximum number of emails to retrieve", + optional: true, + default: 100, + min: 1, + max: 200, + }, + }, + methods: { + async getAssociatedEmails({ + objectType, + objectId, + additionalProperties = [], + limit = 100, + }) { + const properties = [ + ...DEFAULT_EMAIL_PROPERTIES, + ...additionalProperties, + ]; + + const { results } = await this.hubspot.searchCRM({ + object: "emails", + data: { + filterGroups: [ + { + filters: [ + { + propertyName: `associations.${objectType}`, + operator: "EQ", + value: objectId, + }, + ], + }, + ], + properties, + associations: [ + objectType, + ], + sorts: [ + { + propertyName: "hs_timestamp", + direction: "DESCENDING", + }, + ], + limit, + }, + }); + + return results; + }, + }, + async run({ $ }) { + const emails = await this.getAssociatedEmails({ + objectType: this.objectType, + objectId: this.objectId, + additionalProperties: this.additionalProperties, + limit: this.limit, + }); + + const summary = `Successfully retrieved ${emails?.length || 0} email(s)`; + + $.export("$summary", summary); + + return emails || []; + }, +}; diff --git a/components/hubspot/common/constants.mjs b/components/hubspot/common/constants.mjs index f06c89f81b369..156359d385d9e 100644 --- a/components/hubspot/common/constants.mjs +++ b/components/hubspot/common/constants.mjs @@ -172,6 +172,17 @@ const DEFAULT_LEAD_PROPERTIES = [ "hs_associated_company_name", ]; +const DEFAULT_EMAIL_PROPERTIES = [ + "hs_timestamp", + "hs_email_direction", + "hs_email_html", + "hs_email_status", + "hs_email_subject", + "hs_email_text", + "hs_attachment_ids", + "hs_email_headers", +]; + const DEFAULT_MEETING_PROPERTIES = [ "hs_timestamp", "hubspot_owner_id", @@ -225,5 +236,6 @@ export { DEFAULT_LINE_ITEM_PROPERTIES, DEFAULT_LEAD_PROPERTIES, ENGAGEMENT_TYPE_OPTIONS, + DEFAULT_EMAIL_PROPERTIES, DEFAULT_MEETING_PROPERTIES, }; From f40d52a0c13778f9d81d34ff01b0f6d1a63fdd6d Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 20 Aug 2025 23:39:23 -0300 Subject: [PATCH 2/6] package/pnpm bump --- components/hubspot/package.json | 2 +- pnpm-lock.yaml | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/components/hubspot/package.json b/components/hubspot/package.json index 0f2f0c1494063..435936d6ba838 100644 --- a/components/hubspot/package.json +++ b/components/hubspot/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/hubspot", - "version": "1.5.0", + "version": "1.6.0", "description": "Pipedream Hubspot Components", "main": "hubspot.app.mjs", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 957a06ef25bc6..f4c0876c8f99e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10067,8 +10067,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/paazl: - specifiers: {} + components/paazl: {} components/paddle: {} @@ -11185,8 +11184,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/pulumi: - specifiers: {} + components/pulumi: {} components/pumble: dependencies: @@ -15989,8 +15987,7 @@ importers: components/zagomail: {} - components/zammad: - specifiers: {} + components/zammad: {} components/zamzar: dependencies: From de4c691686df58d51bd28e587d5a5db1c78ef978 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 21 Aug 2025 13:01:53 -0300 Subject: [PATCH 3/6] Adjusting action requests --- .../get-associated-emails.mjs | 90 +++++++++---------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs index 550e7681a3cb5..ce2db77839938 100644 --- a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs +++ b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs @@ -44,66 +44,60 @@ export default { label: "Limit", description: "Maximum number of emails to retrieve", optional: true, - default: 100, + default: 20, min: 1, max: 200, }, }, - methods: { - async getAssociatedEmails({ + async run({ $ }) { + const properties = [ + ...DEFAULT_EMAIL_PROPERTIES, + ...(this.additionalProperties || []), + ]; + + const { + objectType, objectId, limit, + } = this; + + const { results } = await this.hubspot.getAssociations({ + $, objectType, objectId, - additionalProperties = [], - limit = 100, - }) { - const properties = [ - ...DEFAULT_EMAIL_PROPERTIES, - ...additionalProperties, - ]; + toObjectType: "emails", + params: { + limit, + }, + }); - const { results } = await this.hubspot.searchCRM({ - object: "emails", - data: { - filterGroups: [ - { - filters: [ - { - propertyName: `associations.${objectType}`, - operator: "EQ", - value: objectId, - }, - ], - }, - ], - properties, - associations: [ - objectType, - ], - sorts: [ - { - propertyName: "hs_timestamp", - direction: "DESCENDING", - }, - ], - limit, - }, - }); + if (!results?.length > 0) { + $.export("$summary", "No emails found"); + return []; + } - return results; - }, - }, - async run({ $ }) { - const emails = await this.getAssociatedEmails({ - objectType: this.objectType, - objectId: this.objectId, - additionalProperties: this.additionalProperties, - limit: this.limit, + const emailIds = results.map((association) => ({ + id: association.toObjectId, + })); + + const { results: emails } = await this.hubspot.batchGetObjects({ + $, + objectType: "emails", + data: { + properties, + inputs: emailIds, + }, }); - const summary = `Successfully retrieved ${emails?.length || 0} email(s)`; + // Sort emails by timestamp in descending order (most recent first) + const sortedEmails = emails?.sort((a, b) => { + const timestampA = new Date(a.properties?.hs_timestamp || 0).getTime(); + const timestampB = new Date(b.properties?.hs_timestamp || 0).getTime(); + return timestampB - timestampA; + }) || []; + + const summary = `Successfully retrieved ${sortedEmails?.length || 0} email(s)`; $.export("$summary", summary); - return emails || []; + return sortedEmails; }, }; From b41f4e228a0e9f271a4113a178e57dc0ac342819 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 21 Aug 2025 13:05:52 -0300 Subject: [PATCH 4/6] Expanding objectType prop --- .../get-associated-emails.mjs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs index ce2db77839938..726920ea3a5ac 100644 --- a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs +++ b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs @@ -1,6 +1,4 @@ -import { - DEFAULT_EMAIL_PROPERTIES, OBJECT_TYPE, OBJECT_TYPES, -} from "../../common/constants.mjs"; +import { DEFAULT_EMAIL_PROPERTIES } from "../../common/constants.mjs"; import hubspot from "../../hubspot.app.mjs"; export default { @@ -12,14 +10,15 @@ export default { props: { hubspot, objectType: { - type: "string", + propDefinition: [ + hubspot, + "objectType", + () => ({ + includeCustom: true, + }), + ], label: "Associated Object Type", description: "The type of the object the emails are associated with", - options: OBJECT_TYPES.filter(({ value }) => [ - OBJECT_TYPE.CONTACT, - OBJECT_TYPE.COMPANY, - OBJECT_TYPE.DEAL, - ].includes(value)), }, objectId: { type: "string", @@ -70,7 +69,7 @@ export default { }); if (!results?.length > 0) { - $.export("$summary", "No emails found"); + $.export("$summary", "No emails found with this association"); return []; } From e4ae1c65410f5fe737e0f9da5b3e2cc88e1623c8 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 21 Aug 2025 18:08:04 -0300 Subject: [PATCH 5/6] Adjusting request limit --- .../actions/get-associated-emails/get-associated-emails.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs index 726920ea3a5ac..f30203cfb344e 100644 --- a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs +++ b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs @@ -45,7 +45,7 @@ export default { optional: true, default: 20, min: 1, - max: 200, + max: 100, }, }, async run({ $ }) { From b956907922dce64de81213020a121f3005ccc6fe Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 21 Aug 2025 20:30:43 -0300 Subject: [PATCH 6/6] Syntax adjustments --- .../actions/get-associated-emails/get-associated-emails.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs index f30203cfb344e..59adbab791ff1 100644 --- a/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs +++ b/components/hubspot/actions/get-associated-emails/get-associated-emails.mjs @@ -87,16 +87,16 @@ export default { }); // Sort emails by timestamp in descending order (most recent first) - const sortedEmails = emails?.sort((a, b) => { + emails?.sort((a, b) => { const timestampA = new Date(a.properties?.hs_timestamp || 0).getTime(); const timestampB = new Date(b.properties?.hs_timestamp || 0).getTime(); return timestampB - timestampA; }) || []; - const summary = `Successfully retrieved ${sortedEmails?.length || 0} email(s)`; + const summary = `Successfully retrieved ${emails.length} email(s)`; $.export("$summary", summary); - return sortedEmails; + return emails; }, };