Hi
After creating company via API we get two records in dashboard
1. Company with name specified in the properties with correct industry, phone and owner id + company address info from hubspot insights
2. Pure company from domain name all info gathered from insights only
How we can get only one company in the end but still be able to set domain and get info from domain (using hubspot insights)
const properties = { domain: 'hubspot.com', name: 'Name', phone: '500500500', organization_size: '10', industry: 'Automotive', type: 'Company', company_on_platform: 'Yes', hs_lead_status: 'Lead', hubspot_owner_id: '1',};const companyHubspot = await hubspotClient.crm.companies.basicApi.create({ properties: properties, associations: [],});
Hey @tabbi-yellow,
When using the API to create a company HubSpot will not deduplicate by the company domain name. This is exepcted behaviour and more information on that can be found here.

In order to avoid duplicates what you should do is first search the CRM using the CRM Search API to see if a company exists with a domain. If a result is found the ID of that company will be returned and you can perform an update operation on the various properties. If no result is found you can assume the company does not exist in the CRM and can create as normal. The process would look something like this:
Step 1: Search the CRM for Company:
POST https://api.hubapi.com/crm/v3/objects/companies/search
BODY
{
"filters": [
{
"propertyName": "domain",
"operator": "EQ",
"value": "marvel.com"
}
]
}
RESPONSE IF EXISTS
{
"total": 1,
"results": [
{
"id": "8109465573",
"properties": {
"createdate": "2023-07-20T13:25:52.999Z",
"domain": "marvel.com",
"hs_lastmodifieddate": "2023-08-08T09:30:31.112Z",
"hs_object_id": "8109465573",
"name": "Marvel"
},
"createdAt": "2023-07-20T13:25:52.999Z",
"updatedAt": "2023-08-08T09:30:31.112Z",
"archived": false
}
]
}
RESPONSE IF NOT EXISTS
{
"total": 0,
"results": []
}
Step 2: If Company exists update:
PATCH https://api.hubapi.com/crm/v3/objects/companies/{companyId}
BODY
{
"properties": {
"prop1": "some value",
"prop2": "some other value"
}
}
Step 3: If Company does not exist create:
POST https://api.hubapi.com/crm/v3/objects/companies/
BODY
{
"properties": {
"prop1": "some value",
"prop2": "some other value"
}
}
If it helps I had to do something similar a few weeks back where I check if the company exists and if it does I do X and if not I do Y. The code is here from line 41. My use case was handling associations.
I hope this helps and best of luck with your project moving forward!
The problem is that we do check before if it exists by domain I even checked in dashboard and it doesn’t exist.
const filter: Filter = { value:'example.com', propertyName: 'domain', operator: 'EQ',};const filterGroup: FilterGroup = { filters: [filter] };const search = { filterGroups: [filterGroup], sorts: [JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })], properties: ['id', 'name', 'domain', 'address', 'city', 'zip', 'state'], limit: 10, after: 0,};try { const result: CollectionResponseWithTotalSimplePublicObjectForwardPaging = await hubspotClient.crm.companies.searchApi.doSearch( search, ); console.log(JSON.stringify(result, null, 2)); if (result.total > 0) { return result.results[0]; }} catch (e) { e.message === 'HTTP request failed' ? console.error(JSON.stringify(e.response, null, 2)) : console.error(e);}
Can you share the response you get back from your search request please?
{
“total”: 0,
“results”: []
}
This only happens for companies with domain that hubspost insights can obtain data so we have two records.
The reason why it happened “Create and associate companies with contacts” option turned ON
Gotcha makes sense thanks for sharing @tabbi-yellow 