diff --git a/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateMembers.ts b/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateMembers.ts index d37bff60ce..fbc0fcedfb 100644 --- a/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateMembers.ts +++ b/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateMembers.ts @@ -46,28 +46,32 @@ export const batchCreateMembers = async ( for (const crowdField of fields) { const hubspotField = memberMapper.getHubspotFieldName(crowdField) - if (crowdField.startsWith('attributes')) { - const attributeName = crowdField.split('.')[1] || null - - if ( - attributeName && - hubspotField && - member.attributes[attributeName]?.default !== undefined - ) { - hsMember.properties[hubspotField] = member.attributes[attributeName].default - } - } else if (crowdField.startsWith('identities')) { - const identityPlatform = crowdField.split('.')[1] || null + // if hubspot e-mail field is mapped to a crowd field, we should ignore it because + // we handle this manually above + if (hubspotField && hubspotField !== 'email') { + if (crowdField.startsWith('attributes')) { + const attributeName = crowdField.split('.')[1] || null + + if ( + attributeName && + hubspotField && + member.attributes[attributeName]?.default !== undefined + ) { + hsMember.properties[hubspotField] = member.attributes[attributeName].default + } + } else if (crowdField.startsWith('identities')) { + const identityPlatform = crowdField.split('.')[1] || null - const identityFound = member.identities.find((i) => i.platform === identityPlatform) + const identityFound = member.identities.find((i) => i.platform === identityPlatform) - if (identityPlatform && hubspotField && identityFound) { - hsMember.properties[hubspotField] = identityFound.username + if (identityPlatform && hubspotField && identityFound) { + hsMember.properties[hubspotField] = identityFound.username + } + } else if (crowdField === 'organizationName') { + // send latest org of member as value + } else if (hubspotField && member[crowdField] !== undefined) { + hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField) } - } else if (crowdField === 'organizationName') { - // send latest org of member as value - } else if (hubspotField && member[crowdField] !== undefined) { - hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField) } } diff --git a/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateOrganizations.ts b/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateOrganizations.ts index 6f2873d7e0..4084b582df 100644 --- a/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateOrganizations.ts +++ b/services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateOrganizations.ts @@ -47,12 +47,15 @@ export const batchCreateOrganizations = async ( for (const crowdField of fields) { const hubspotField = organizationMapper.getHubspotFieldName(crowdField) - - if (hubspotField && organization[crowdField] !== undefined) { - hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue( - organization, - crowdField, - ) + // if hubspot domain field is mapped to a crowd field, we should ignore it + // because we handle this manually above + if (hubspotField && hubspotField !== 'domain') { + if (organization[crowdField] !== undefined) { + hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue( + organization, + crowdField, + ) + } } } diff --git a/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateMembers.ts b/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateMembers.ts index 6ddd9d7661..493d17aff9 100644 --- a/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateMembers.ts +++ b/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateMembers.ts @@ -43,28 +43,32 @@ export const batchUpdateMembers = async ( for (const crowdField of fields) { const hubspotField = memberMapper.getHubspotFieldName(crowdField) - if (crowdField.startsWith('attributes')) { - const attributeName = crowdField.split('.')[1] || null - - if ( - attributeName && - hubspotField && - member.attributes[attributeName]?.default !== undefined - ) { - hsMember.properties[hubspotField] = member.attributes[attributeName].default + // if hubspot e-mail field is mapped to a crowd field, we should ignore it because + // we handle this manually above + if (hubspotField && hubspotField !== 'email') { + if (crowdField.startsWith('attributes')) { + const attributeName = crowdField.split('.')[1] || null + + if ( + attributeName && + hubspotField && + member.attributes[attributeName]?.default !== undefined + ) { + hsMember.properties[hubspotField] = member.attributes[attributeName].default + } + } else if (crowdField.startsWith('identities')) { + const identityPlatform = crowdField.split('.')[1] || null + + const identityFound = member.identities.find((i) => i.platform === identityPlatform) + + if (identityPlatform && hubspotField && identityFound) { + hsMember.properties[hubspotField] = identityFound.username + } + } else if (crowdField === 'organizationName') { + // send latest org of member as value + } else if (hubspotField && member[crowdField] !== undefined) { + hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField) } - } else if (crowdField.startsWith('identities')) { - const identityPlatform = crowdField.split('.')[1] || null - - const identityFound = member.identities.find((i) => i.platform === identityPlatform) - - if (identityPlatform && hubspotField && identityFound) { - hsMember.properties[hubspotField] = identityFound.username - } - } else if (crowdField === 'organizationName') { - // send latest org of member as value - } else if (hubspotField && member[crowdField] !== undefined) { - hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField) } } diff --git a/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateOrganizations.ts b/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateOrganizations.ts index 065de08d25..ceee4e788e 100644 --- a/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateOrganizations.ts +++ b/services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateOrganizations.ts @@ -43,12 +43,15 @@ export const batchUpdateOrganizations = async ( for (const crowdField of fields) { const hubspotField = organizationMapper.getHubspotFieldName(crowdField) - - if (hubspotField && organization[crowdField] !== undefined) { - hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue( - organization, - crowdField, - ) + // if hubspot domain field is mapped to a crowd field, we should ignore it + // because we handle this manually above + if (hubspotField && hubspotField !== 'domain') { + if (organization[crowdField] !== undefined) { + hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue( + organization, + crowdField, + ) + } } }