Con este codigo Python me funciona para crear empresas nuevas, pero si en el fichero CSV tengo registros que ya existen y se les ha modificado algun dato, querria que me lo actualizara y no lo hace.
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()