Hello,
I’m trying to import CSV files with the /crm/v3/imports endpoint, without any success so far. I’ve read thoroughly the issue here and some others, but still I can’t find a way to make it work. As mentionned by @JakeBreaksStuff I’m surprised by the lack of documentation, and I would also add that a few hints in the HTPP response (“Bad request” really don’t help) would be really helpful (even more than a documentation !).
At first I had 415 errors and now 400, can you confirm me I’m still on the right way ? ![]()
I’m not sure how to send the files param. nodejs form-data does not accept arrays, so I try without array, or with files[] or files[0] or files with JSON.stringify([file…]) but no solution worked, always get a 400 Bad Request.
Also I have to stringify the importRequest object as form-data does not work with nested object (issue here).
Thus I’m not sure where’s my issue : the files param ? the importRequest param ? something wrong in my column mapping vs CSV ? I’ve checked and dumped formData several times to be sure
Again, giving a hint in the HTTP response data would really help…
So here is my code :
const dateFormat = 'DD/MM/YYYY';
const csvFile = fs.readFileSync(hubspotExportFileName);
const csvFilePath = `${__dirname}/../../${csvFile}`;
const accessToken = await getHubspotAccessToken();
const importRequest = {
name: `import-${moment().format('YYYYMMDD')}`,
files: [
{
fileName: csvFile,
fileFormat: 'CSV',
dateFormat,
fileImportPage: {
hasHeader: true,
columnMappings: [
{
ignored: false,
columnName: 'email',
idColumnType: 'HUBSPOT_ALTERNATE_ID',
propertyName: 'email',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'firstname',
idColumnType: null,
propertyName: 'firstname',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'contact_role',
idColumnType: null,
propertyName: 'contact_role',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'zip',
idColumnType: null,
propertyName: 'zip',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'subscription_funnel_step',
idColumnType: null,
propertyName: 'subscription_funnel_step',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'approval_date',
idColumnType: null,
propertyName: 'approval_date',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'delivery_date',
idColumnType: null,
propertyName: 'delivery_date',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
{
ignored: false,
columnName: 'fleet_manager',
idColumnType: null,
propertyName: 'fleet_manager',
foreignKeyType: null,
columnObjectType: 'CONTACT',
associationIdentifierColumn: false,
},
],
},
},
],
};
const form = new FormData();
form.append('importRequest', JSON.stringify(importRequest));
form.append('files[0]', fs.createReadStream(csvFilePath));
const url = `https://api.hubapi.com/crm/v3/imports`
const config = {
headers: {
'content-type': 'multipart/form-data',
Authorization: `Bearer ${accessToken}`,
},
};
try {
await axios.post(url, form, config);
} catch (error) {
console.dir(error);
}
and here is what my CSV file look like :

Any idea how to make this works ?
Thank you !
Olivier