date format in impor file

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)

@Bryantworks ,

Anything standing out to you?

Hi @DMenendez,

Can you provide a sample of the csv file you’re trying to import ?
I don’t see anything wrong with your code, which makes me think it has something to do with the cells content.

Hi Ludwig!

Actually I solved the poblem by putting ‘DAY_MONTH_YEAR’ after “name”:“Import API Test” instead of using it in the file’s parameters and worked fine.

Thanks for reaching!

Hey, good to know you solved it :slightly_smiling_face:
@dennisedson, shouldn’t the doc be updated to reflect the correct placement of that parameter in the JSON payload ?
The doc does say the date parameter should be within the file array :

@LMeert , @DMenendez ,

Will get this to the docs team to update!

Thanks for adding the solution @DMenendez

What do you mean by “instead of using it in the file’s parameters”? Where did you put it?