Hubspot's CRM import API with Node SDK

This is how my importRequest JSON object looks like. I just stringify it using JSON.stringify.

const importRequest = {
 name: "test_import",
 files: [
 {
 fileName: "accounts.csv",
 fileFormat: "CSV",
 fileImportPage: {
 hasHeader: true,
 columnMappings: [
 {
 columnName: "Email",
 propertyName: "email",
 columnObjectType: "CONTACT",
 },
 {
 columnName: "First name",
 propertyName: "firstname",
 columnObjectType: "CONTACT",
 },
 {
 columnName: "Last name",
 propertyName: "lastname",
 columnObjectType: "CONTACT",
 },
 {
 columnName: "Phone number",
 propertyName: "phone",
 columnObjectType: "CONTACT",
 },
 {
 columnName: "Created At",
 propertyName: "createdat",
 columnObjectType: "CONTACT",
 },
 ],
 },
 },
 ],
 };

This is how my csv file looks like. It’s placed in the same folder as the index.js file.

All I get is the notorious

body: {
 status: 'error',
 message: 'Unable to process JSON',
 correlationId: '9ea8d506-36a3-4cea-b0a8-33f336d6233c'
},

error. ANY HELP is appreciated. I have tried all formating checks from the community posts but none seem to work for me.

Got it to work. The Node SDK’s documentation is outdated. VSCode’s suggestions saved me.
npm docs say this:

const result = await hubspotClient.crm.imports.coreApi.create(JSON.stringify(importRequest), importFileReadStream)

While in reality, importFileReadStream is the first parameter and importRequest is the second, not the other way around.

const result = await hubspotClient.crm.imports.coreApi.create(importFileReadStream, JSON.stringify(importRequest))

I hope this helps someone before they fall down this rabbithole and waste 4 hours because of inaccurate documentation.

Hubspot team! Please!! :folded_hands:t2: Do something!

“Argument of type ‘ReadStream’ is not assignable to parameter of type ‘HttpFile’” is the error I am facing any ideas about this? thanks

Abdullah, thanks for sharing. Any chance you know what the request should look like without the SDK. Maybe a sample post request. No worries, if you don’t know :slightly_smiling_face: