Loading...
Started by Anga Matsuluka • Jul 21, 2025 1:47 PM
Total Replies
2
Participants
2
Activity
Quiet
Duration
1:47 PM
Thread starter
status: 'error',
message: 'Authentication credentials not found. This API supports OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview',
correlationId: '144e5d55-d552-43b4-9bbb-ffd52036037f',
category: 'INVALID_AUTHENTICATION'
}
async function removeAssociation(dealId, contactId, associationTypeId) {
if (!associationTypeId) {
throw new Error('associationTypeId is required to remove a specific association label');
}
console.log('removing association');
await axios.delete(
`${HUBSPOT_BASE_URL}/crm/v4/objects/deals/${dealId}/associations/contacts/${contactId}`,
{
headers: hubspotHeaders,
params: {
associationTypeId: associationTypeId
}
}
);
console.log(`Removed association type ${associationTypeId} between deal ${dealId} and contact ${contactId}`);
}
async function addAssociation(dealId, contactId) {
//await new Promise(resolve => setTimeout(resolve, 3000));
console.log('add association');
console.log(`Deal id ${dealId}, contacts id: ${contactId}`);
await axios.put(`${HUBSPOT_BASE_URL}/crm/v4/objects/deals/${dealId}/associations/default/contacts/${contactId}`, {
headers: hubspotHeaders
});
}// 2️⃣ Remove labeled association if email changed
if (existingEmail && existingEmail !== billingEmail) {
console.log(`[BillingSync] Removing existing Billing Contact association for contact ${existingBillingContactId}`);
await removeAssociation(dealId, existingBillingContactId, 99);
console.log(`[BillingSync] Adding default (unlabeled) association`);
await addAssociation(dealId, existingBillingContactId);
}
2 messages in thread