Uploading files to HubSpot CRM in NodeJs
Posted By : Nisheet Sharma | 26-Oct-2018
HubSpot is a Customer Relationship Management (CRM) tool, which businesses can utilize to systemize, track and evolve their relationships with their leads & existing clients.
One of the features included in your HubSpot account is the File Manager. You can use it to store, share and organize documents with members of your internal team(s). You can even link them to your customers as attachments with custom activity notes or engagements.
You'll need your Hubspot API Integration Key, which can be found on Integrations page under HubSpot API Key tab. Additionally, you can create a folder in your HubSpot account, where you wish to store a file. Once you have successfully created a folder you can use its unique ID or path in your request to save your files inside it.
const fs = require('fs');
const request = require('request');
const hapikey = 'your-hubspot-integration-key';
const baseUrl = 'https://api.hubapi.com';
var fileManagerUrl = `${baseUrl}/filemanager/api/v2/files?hapikey=${hapikey}`;
var options = {
url: fileManagerUrl,
headers: { 'Content-Type': 'multipart/form-data' },
method: "POST",
formData: {
file: fs.createReadStream('path/to/the/file/you/want/to/upload'),
file_names: "fileName", /* Optional */
folder_paths: '/path/to/folder/inside/hubspot', /* Optional */
folder_id: 123456789 /* Optional */
}
};
request(options, someCustomCallback);
The properties used in the form data are as follows:
1. file_names - It is an optional field of type string, you can use it to rename the file you are uploading to HubSpot. If we don't provide this, then HubSpot will use the existing file name.
2. file - It is a required field, that will contain the multipart form-data of the file you are uploading.
3. folder_paths - It is another optional field of type string. If no folder_paths or
4. folder_id - This is an optional field as well. It's of type long. We can use it instead of the folder path. Every folder created on HubSpot will have a unique ID, so you can provide the destination folder's ID here.
We can pass the following additional query parameters as well if and when required.
1. overwrite - It takes a boolean value. If set to true, it will overwrite any existing file matching the provided file name inside the File Manager.
2. hidden - This takes a boolean value as well. Set it to true, to hide the file in the HubSpot File Manager. This will still let the file be accessible in all linked notes/engagements though.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Nisheet Sharma
Nisheet is a Full Stack Developer (MEAN). He is familiar with C, C++, Java, Html, Css, JavaScript, MySql, MongoDb, AngularJs, NodeJs, ExpressJs.