Hi all,
I’m trying to do a contact import via API. So far my code is working except fro dates. In my CSV file the dates are in DMY format and in my code that’s specified but once I run it I get an error in the import saying that MDY can’t recognize the date. This is the code I’m using:
import requests
import json
import os
url='https://api.hubapi.com/crm/v3/imports?hapikey={my hapi key}'
data={
"name": "Import API Test",
"files": [
{
"fileName": "cargue test hubspot.csv",
"fileFormat": "CSV",
#This is where I modify the date format
"dateFormat": "DAY_MONTH_YEAR",
"fileImportPage": {
"hasHeader": True,
"columnMappings":[
{
"ignored": False,
"columnName": "email",
"idColumnType": None,
"propertyName": "email",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_telefono",
"idColumnType": None,
"propertyName": "co_smb_telefono",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_nombre",
"idColumnType": None,
"propertyName": "co_smb_nombre",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_marca",
"idColumnType": None,
"propertyName": "co_smb_marca",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_onboarding_status",
"idColumnType": None,
"propertyName": "co_smb_onboarding_status",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_company_name",
"idColumnType": None,
"propertyName": "co_smb_company_name",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_mcc_code",
"idColumnType": None,
"propertyName": "co_smb_mcc_code",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_document_type",
"idColumnType": None,
"propertyName": "co_smb_document_type",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_document_no",
"idColumnType": None,
"propertyName": "co_smb_document_number",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_merchant_id",
"idColumnType": None,
"propertyName": "co_smb_merchant_id",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_account_id",
"idColumnType": None,
"propertyName": "co_smb_account_id",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_status_account",
"idColumnType": None,
"propertyName": "co_smb_status_account",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_status_merchant",
"idColumnType": None,
"propertyName": "co_smb_status_merchant",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_fecha_creacion",
"idColumnType": None,
"propertyName": "co_smb_fecha_creacion",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False,
"dateFormat": "DAY_MONTH_YEAR"
},
{
"ignored": False,
"columnName": "co_smb_mcc_description",
"idColumnType": None,
"propertyName": "co_smb_mcc_description",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_primera_trx",
"idColumnType": None,
"propertyName": "co_smb_primera_trx",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_fecha_primera_trx",
"idColumnType": None,
"propertyName": "co_smb_fecha_primera_trx",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False,
"dateFormat": "DAY_MONTH_YEAR"
},
{
"ignored": False,
"columnName": "co_smb_fecha_ultima_trx",
"idColumnType": None,
"propertyName": "co_smb_fecha_ultima_trx",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False,
"dateFormat": "DAY_MONTH_YEAR"
},
{
"ignored": False,
"columnName": "co_smb_inactividad",
"idColumnType": None,
"propertyName": "co_smb_inactividad",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
},
{
"ignored": False,
"columnName": "co_smb_ab_testing",
"idColumnType": None,
"propertyName": "co_smb_ab_testing",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifierColumn": False
}
]
}
}
]
}
datastring = json.dumps(data)
payload = {"importRequest": datastring}
path='whatever the path is'
files = [
('files', open(path, 'r'))
]
response = requests.request("POST", url, data=payload, files=files)
