# Import companies with Python

**URL:** <https://community.hubspot.com/t/import-companies-with-python/46015>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [October 27, 2021, 8:01am UTC](https://community.hubspot.com/t/import-companies-with-python/46015 "2021-10-27T08:01:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcmm](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@marcmm](https://community.hubspot.com/u/marcmm)\
**Post date:** [October 27, 2021, 8:01am UTC](https://community.hubspot.com/t/import-companies-with-python/46015/1 "2021-10-27T08:01:44Z")

</div>

This Python code works for me to create new companies from a csv file, but if I have records in the file that already exist, I would need to update the information if there are changes.

import requests  
import json  
import csv

def import\_companies():  
post\_url = “[https://api.hubapi.com/crm/v3/imports?hapikey=YourHapikey](https://api.hubapi.com/crm/v3/imports?hapikey=YourHapikey)”  
payload = {  
“name”: “import\_companies”,  
“files”: [  
{  
“fileName”: “companies.csv”,  
“fileformat”: “CSV”,  
“fileImportPage”: {  
“hasHeader”: True,  
“columnMappings”: [  
{  
“ignored”: False,  
“columnName”: “Nombre”,  
“propertyName”: “name”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Dominio”,  
“idColumnType”: “HUBSPOT\_ALTERNATE\_ID”,  
“propertyName”: “domain”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Telefono”,  
“propertyName”: “phone”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “CP”,  
“propertyName”: “zip”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Direccion”,  
“propertyName”: “address”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Poblacion”,  
“propertyName”: “city”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Provincia”,  
“propertyName”: “state”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Pais”,  
“propertyName”: “country”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “Comercial”,  
“propertyName”: “hubspot\_owner\_id”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
},  
{  
“ignored”: False,  
“columnName”: “hs\_object\_id”,  
“propertyName”: “hs\_object\_id”,  
“columnObjectType”: “COMPANY”,  
“associationIdentifierColumn”: False  
}  
]  
}  
}  
]  
}  
files = {  
‘importRequest’: (None, json.dumps(payload), ‘application/json’),  
‘files’: open(‘companies.csv’, ‘rb’)  
}  
res = requests.post(post\_url, files=files)  
print(res)  
print(res.text)

import\_companies()

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 27, 2021, 3:03pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/2 "2021-10-27T15:03:59Z")

</div>

@marcmm ,

I am unclear what the actual question is here 🤔

---

<div class="post-metadata">

**Author:** ![marcmm](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@marcmm](https://community.hubspot.com/u/marcmm)\
**Post date:** [October 27, 2021, 4:04pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/3 "2021-10-27T16:04:16Z")

</div>

The code works to insert new companies, but it does not work to update data of existing companies.  
I would need to be able to update company data.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 28, 2021, 2:29pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/4 "2021-10-28T14:29:12Z")

</div>

Gotchya. Presently, HubSpot does not deduplicate companies via the domain name as indicated on [this page](https://knowledge.hubspot.com/crm-setup/deduplication-of-contacts-companies-deals-tickets). You would need to build some logic into your app to compare the data.

@akaiser , @wfong , @JBeatty do any of you all have some ideas on this?

---

<div class="post-metadata">

**Author:** ![JBeatty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbeatty/32/52252_2.png) [@JBeatty](https://community.hubspot.com/u/JBeatty)\
**Post date:** [October 31, 2021, 7:34pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/5 "2021-10-31T19:34:36Z")

</div>

I would suggest doing an export of company domains and HubSpot Ids, that way you could cross look up them, and update them based on the Ids.

---

<div class="post-metadata">

**Author:** ![TArnoldGZ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tarnoldgz/32/6413_2.png) [@TArnoldGZ](https://community.hubspot.com/u/TArnoldGZ)\
**Post date:** [August 8, 2022, 2:43pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/6 "2022-08-08T14:43:17Z")

</div>

When you say “update them based on IDs,” do you mean a bulk Company Domain update based on Company ID? Is that possible given the Company ID property is itself a unique identifier?

---

<div class="post-metadata">

**Author:** ![LGarcia41](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@LGarcia41](https://community.hubspot.com/u/LGarcia41)\
**Post date:** [October 6, 2022, 12:04pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/7 "2022-10-06T12:04:46Z")

</div>

Hi, how would this look like switching to Access token and private apps? It seems that the example given online doens’t work

---

<div class="post-metadata">

**Author:** ![EPosa](https://avatars.discourse-cdn.com/v4/letter/e/ccd318/32.png) [@EPosa](https://community.hubspot.com/u/EPosa)\
**Post date:** [February 8, 2023, 3:12pm UTC](https://community.hubspot.com/t/import-companies-with-python/46015/8 "2023-02-08T15:12:01Z")

</div>

Hi @marcmm,  
Automated import service like Help Desk Migration can help you avoid coding so that you save much time and effort. You can arrange a custom import and see how it goes using a free demo import. Check how this solution works here: [How it works | Help Desk Migration Service](https://help-desk-migration.com/how-it-works/)
