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
id is provided, HubSpot will store the file in the root directory. Otherwise, it'll store it inside the folder whose path is provided.
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.

About Author

Author Image
Nisheet Sharma

Nisheet is a Full Stack Developer (MEAN). He is familiar with C, C++, Java, Html, Css, JavaScript, MySql, MongoDb, AngularJs, NodeJs, ExpressJs.

Request for Proposal

Name is required

Comment is required

Sending message..