关联联系人至公司时出现非预期关联的技术求助
如何避免HubSpot批量关联联系人与公司时创建未指定的关联类型?
我需要给两位联系人分别设置不同的关联类型关联到同一公司:
- 联系人11751用
company_to_contact(关联ID 1)关联公司9314823150 - 联系人11752用
company_to_contact_unlabeled(关联ID 279)关联同一公司
调用{{baseUrl}}/crm/v4/associations/contacts/companies/batch/create接口,请求体如下:
{ "inputs": [ { "from": "11751", "to": "9314823150", "types": [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "1" } ] }, { "from": "11752", "to": "9314823150", "types": [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "279" } ] } ] }
但查询公司关联时,返回结果显示两位联系人同时拥有两种关联类型:
{ "id": "9314823150", "properties": { "createdate": "2023-12-18T15:53:21.146Z", "domain": null, "hs_lastmodifieddate": "2024-01-03T08:04:04.525Z", "hs_object_id": "9314823150", "name": "KBJ Miljø ApS" }, "createdAt": "2023-12-18T15:53:21.146Z", "updatedAt": "2024-01-03T08:04:04.525Z", "archived": false, "associations": { "contacts": { "results": [ { "id": "11751", "type": "company_to_contact" }, { "id": "11752", "type": "company_to_contact" }, { "id": "11751", "type": "company_to_contact_unlabeled" }, { "id": "11752", "type": "company_to_contact_unlabeled" } ] } } }
解决方法
问题出在batch/create接口是添加关联而非替换关联,且HubSpot中company_to_contact与company_to_contact_unlabeled存在自动关联机制——创建其中一个时会自动生成另一个。要实现单一关联类型的需求,需按以下步骤操作:
先清理已有关联
调用{{baseUrl}}/crm/v4/associations/contacts/companies/batch/archive接口,删除联系人与目标公司之间的所有关联类型,请求体示例:{ "inputs": [ { "from": "11751", "to": "9314823150", "types": [ {"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "1"}, {"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "279"} ] }, { "from": "11752", "to": "9314823150", "types": [ {"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "1"}, {"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "279"} ] } ] }使用
batch/upsert接口设置唯一关联
改用{{baseUrl}}/crm/v4/associations/contacts/companies/batch/upsert接口,该接口会替换指定对象对的关联类型,而非追加。请求体与原create接口一致:{ "inputs": [ { "from": "11751", "to": "9314823150", "types": [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "1" } ] }, { "from": "11752", "to": "9314823150", "types": [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": "279" } ] } ] }
这样操作后,每个联系人只会保留你指定的单一关联类型,不会生成额外的未指定关联。
内容的提问来源于stack exchange,提问作者Lars Ladegaard
相关产品推荐
相关产品推荐

