HubSpot CRM Import API Returns 415 Error When Uploading Contact Data

I’m trying to bulk upload contact information to HubSpot using their CRM imports endpoint but keep getting a 415 status code error. My contact data includes fields like last name, email, phone, state, and company website. I’ve tested with both CSV and Excel formats but neither works.

import requests
import json

api_endpoint = 'http://api.hubapi.com/crm/v3/imports?hapikey=abc....xyz'

data_file = "contact_upload.csv"

request_headers = {'accept': 'application/json'}

payload = {
    "name": "bulk_contact_import",
    "files": [
        {
            "fileName": data_file,
            "fileFormat": "CSV",
            "fileImportPage": {
                "hasHeader": True,
                "columnMappings": [
                    {
                        "ignored": False,
                        "columnName": "LastName",
                        "idColumnType": None,
                        "propertyName": "lastname",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifiedColumn": False
                    },
                    {
                        "ignored": False,
                        "columnName": "Email Address",
                        "idColumnType": None,
                        "propertyName": "email",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifiedColumn": False
                    },
                    {
                        "ignored": False,
                        "columnName": "Phone_Number",
                        "idColumnType": None,
                        "propertyName": "phone",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifiedColumn": False
                    },
                    {
                        "ignored": False,
                        "columnName": "State",
                        "idColumnType": None,
                        "propertyName": "state",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifiedColumn": False
                    },
                    {
                        "ignored": False,
                        "columnName": "Company Website",
                        "idColumnType": None,
                        "propertyName": "company",
                        "foreignKeyType": None,
                        "columnObjectType": "CONTACT",
                        "associationIdentifiedColumn": False
                    }
                ]
            }
        }
    ]
}

response = requests.post(url=api_endpoint, data=payload, headers=request_headers)

print(response.status_code)
print(response.text)

The file path is correct and my API key works for other requests. I’ve double checked that my CSV column headers match the property names in HubSpot. The 415 error suggests there might be an issue with the content type or request format but I’m not sure what I’m missing. Has anyone successfully used this API endpoint before?

The issue is definitely your multipart/form-data handling. HubSpot’s imports API needs a proper multipart request - you can’t just send everything as JSON. I hit the same problem during our customer data migration last year. You’re trying to embed file metadata in JSON, but the API wants the actual CSV file as multipart data with the import config sent separately. Use the files parameter in requests.post() for your CSV and send the import configuration on its own. Don’t forget to set the right Content-Type header for multipart uploads - the API’s picky about this. Watch out for file encoding too. I’ve gotten 415 errors from CSV encoding problems even when the request structure was perfect.

You’re sending the request data wrong. You’re using data=payload which sends form-encoded data, but HubSpot’s imports API wants JSON. Switch to json=payload instead of data=payload in your requests.post() call.

You also need to handle file uploads differently. The imports API needs two steps - upload the file first to get a file ID, then create the import job using that ID. You can’t just dump the file content into the JSON payload.

I hit this exact issue last month migrating our contact database. The docs aren’t super clear about this, but once you split file upload from import creation, it works fine.