APIs & Integrations

marcmm
Membro

Import companies with Python

resolver

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 Avaliação positiva
1 Solução aceita
JBeatty
Solução
Orientador(a) | Parceiro Diamante
Orientador(a) | Parceiro Diamante

Import companies with Python

resolver

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

Exibir solução no post original

7 Respostas 7
EPosa
Membro

Import companies with Python

resolver

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 Avaliação positiva
dennisedson
Equipe de Produto da HubSpot
Equipe de Produto da HubSpot

Import companies with Python

resolver

@marcmm ,

I am unclear what the actual question is here 🤔

0 Avaliação positiva
marcmm
Membro

Import companies with Python

resolver

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 Avaliação positiva
dennisedson
Equipe de Produto da HubSpot
Equipe de Produto da HubSpot

Import companies with Python

resolver

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 Avaliação positiva
JBeatty
Solução
Orientador(a) | Parceiro Diamante
Orientador(a) | Parceiro Diamante

Import companies with Python

resolver

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
Membro

Import companies with Python

resolver

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

0 Avaliação positiva
TArnoldGZ
Participante

Import companies with Python

resolver

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 Avaliação positiva