Created
July 28, 2025 18:56
-
-
Save HubSpotHanevold/d8eca73147b01ad2489e2022fcc94202 to your computer and use it in GitHub Desktop.
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
| const axios = require('axios'); | |
| exports.main = async (event, callback) => { | |
| const hs_object_id = event.inputFields['hs_object_id']; | |
| let data = JSON.stringify({ | |
| "filterGroups": [ | |
| { | |
| "filters": [ | |
| { | |
| "propertyName": "conference_array", | |
| "operator": "HAS_PROPERTY" | |
| }, | |
| { | |
| "propertyName": "associations.deal", | |
| "operator": "EQ", | |
| "value": hs_object_id | |
| } | |
| ] | |
| } | |
| ], | |
| "properties": ["conference_array"] | |
| }); | |
| let config = { | |
| method: 'post', | |
| maxBodyLength: Infinity, | |
| url: 'https://api.hubapi.com/crm/v3/objects/contacts/search', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': 'Bearer TEST' | |
| }, | |
| data : data | |
| }; | |
| try { | |
| const response = await axios.request(config); | |
| const results = response.data.results; | |
| // Merge and deduplicate conference_arrays | |
| let mergedArray = []; | |
| const seen = new Set(); | |
| results.forEach(contact => { | |
| const rawArray = contact.properties?.conference_array; | |
| if (!rawArray) return; | |
| let parsedArray; | |
| try { | |
| parsedArray = JSON.parse(rawArray); // in case it's a JSON string | |
| } catch (e) { | |
| parsedArray = rawArray; // assume it's already an object/array | |
| } | |
| if (Array.isArray(parsedArray)) { | |
| parsedArray.forEach(entry => { | |
| const key = JSON.stringify(entry); // simple deduplication by content | |
| if (!seen.has(key)) { | |
| seen.add(key); | |
| mergedArray.push(entry); | |
| } | |
| }); | |
| } | |
| }); | |
| callback({ | |
| outputFields: { | |
| combined_conference_array: JSON.stringify(mergedArray) | |
| } | |
| }); | |
| } catch (error) { | |
| console.error("❌ HubSpot API error:", error.response?.data || error.message); | |
| callback({ | |
| outputFields: { | |
| combined_conference_array: "[]" | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This: Looks at all associated contacts that have a 'conference array' value. Then, compiles all those arrays into one. Then, you can use this output to make a bulk association request from Deal <> Conference.