We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Dec 18, 2019 10:18 AM
I am trying to upload file to filemanager but getting 400 error in responce, here is the code (JavaScript/Express.js):
app.post('/hubspot-files-api', upload.any(), function (req, res) { var data = new FormData(); data.append("files", fs.createReadStream(path.join(__dirname, '../files/robots.txt'))); data.append("folder_ids", "Brand Audit form file"); axios.post('http://api.hubapi.com/filemanager/api/v2/files?hapikey=key', data, { headers: { 'Content-Type': 'multipart/form-data' } }) .then((res) => { console.log(`statusCode: ${res.statusCode}`) res.send('OK'); }) .catch((error) => { console.error(error.message); }) });
Any ideas what I am doing wrong here?
Dec 23, 2019 1:34 PM
Hey @vladbesson ,
It's tough to say for sure by just looking at your code, but my initial thought here is that the `folder_ids` field needs to be within a `data` field. Here's the Python example code we provide, and `folder_paths` appears to be within the `data` field:
import requests files = {'files': open('/path/on/your/local-computer/report.xls', 'rb')} r = requests.post( 'http://api.hubapi.com/filemanager/api/v2/files?hapikey=demo', data={ "folder_paths": "folder-in-the-cms-file-manager/subfolder" }, files=files)
https://developers.hubspot.com/docs/methods/files/post_files