APIs & Integrations

marcmm
Member

Import companies with Python

SOLVE

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
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Import companies with Python

SOLVE

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

7 Replies 7
EPosa
Member

Import companies with Python

SOLVE

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: https://help-desk-migration.com/how-it-works/

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Import companies with Python

SOLVE

@marcmm ,

I am unclear what the actual question is here 🤔

0 Upvotes
marcmm
Member

Import companies with Python

SOLVE

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
HubSpot Product Team
HubSpot Product Team

Import companies with Python

SOLVE

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?

0 Upvotes
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Import companies with Python

SOLVE

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

LGarcia41
Member

Import companies with Python

SOLVE

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

0 Upvotes
TArnoldGZ
Participant

Import companies with Python

SOLVE

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?

0 Upvotes