Import companies with Python

SOLVE
marcmm
Member

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"
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()

0 Upvotes
1 Accepted solution

Accepted Solutions
JBeatty
Solution
Top Contributor | Platinum Partner

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.

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post

4 Replies 4
dennisedson
Community Manager

@marcmm ,

I am unclear what the actual question is here 🤔

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
marcmm
Member

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.

0 Upvotes
dennisedson
Community Manager

Gotchya.  Presently, HubSpot does not deduplicate companies via the domain name as indicated on  this page.  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?

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
JBeatty
Solution
Top Contributor | Platinum Partner

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.

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post