APIs & Integrations

KEntwistle
Participant

Update contact property to 'blank' when bulk importing CRM data

I am using the CRM API to bulk import contact data with Python.

 

The code (example from the documentation) is:

 

import requests
import json
import os

# insert your api key here
url = "https://api.hubapi.com/crm/v3/imports?hapikey={{}}"

data = {
    "name": "test_import",
    "files": [
        {
            "fileName": "test_import.csv",
            "fileFormat": "CSV",
            "fileImportPage": {
                "hasHeader": True,
                "columnMappings": [
                    {
                        "ignored": False,
                        "columnName": "First Name",
                        "idColumnType": None,
                        "propertyName": "firstname",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifierColumn": False
                    },
                    {
                        "ignored": False,
                        "columnName": "Email",
                        "idColumnType": "HUBSPOT_ALTERNATE_ID",
                        "propertyName": "email",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifierColumn": False
                    }
                ]
            }
        }
    ]}

datastring = json.dumps(data)

payload = {"importRequest": datastring}

current_dir = os.path.dirname(__file__)
relative_path = "./test_import.csv"

absolute_file_path = os.path.join(current_dir, relative_path)

files = [
    ('files', open(absolute_file_path, 'r'))
]
print(files)


response = requests.request("POST", url, data=payload, files=files)

print(response.text.encode('utf8'))
print(response.status_code)

 

It's working fine except for where a value already exists in a property field for a contact, and I want to clear the value rather than replace it with a new value.

 

We have some contact updates running through Zapier where it is possible to indicate that you wish to clear a field using $$CLEAR$$ as the property value.

 

Is there something I can add to the above code that indicates existing values should be cleared where the field is empty in the imported CSV file?

 

Thanks!

0 Upvotes
2 Replies 2
VLorente
Member

Update contact property to 'blank' when bulk importing CRM data

I have the same issue.

 

The @FelipeFelix 's work-around gave me an idea. I can not use the Hubspot GUI for a massive update because this is a full automated import process that needs to run daily, but the python code can write something like $$CLEAR$$ (as @KEntwistle   mentioned) or just a ∅ and then use bulk updates to replace that by the empty string.

Anyway this is an ugly patch because then perhaps it would have been better to not use the import api and only use the batch api.

 

I think the import api call should have something to solve this without having to do extra work-arounds that can be difficult to implement when you are modeling with several custom schemas.

0 Upvotes
FelipeFelix
Top Contributor

Update contact property to 'blank' when bulk importing CRM data

Hi @KEntwistle!

HubSpot's import system actually ignores empty cells. But there's is a workaround:

- Create a new property, maybe a single-line text one;

- At your CSV file, fill that property with some data, like "XXX";

- After importing go to your Contact area in HubSpot and filter by everyone with that property with "XXX" data;
- Mass edit these contacts clearing whatever you want 🙂

Best,
Felipe Felix