APIs & Integrations

Not applicable

Hubspot API File Manager Upload Issues

I’m attempting to use the Hubspot API to upload files dynamically from my website to our HubSpot file system. I’m using PHP / cURL to do this with code similar to the following:

<?php

$params = "--custom-boundary-123456789\r\n".
		"Content-Disposition: form-data; name=\"folder_paths\"\r\n\r\n".
		"static\r\n".
		"--custom-boundary-123456789\r\n".
		"Content-Disposition: form-data; name=\"files[]\"; filename=\"file-a.html\"\r\n".
		"Content-Type: text/html\r\n\r\n".
		"<div>Content for file-a.html here...</div>\r\n".
		"--custom-boundary-123456789\r\n".
		"Content-Disposition: form-data; name=\"files[]\"; filename=\"file-b.html\"\r\n".
		"Content-Type: text/html\r\n\r\n".
		"<div>Content for file-b.html here...</div>\r\n".
		"--custom-boundary-123456789--";

$request_headers = array('Content-Type: multipart/form-data; boundary=--custom-boundary-123456789');

$ch = curl_init('http://api.hubapi.com/filemanager/api/v2/files?hapikey=my-api-key-here&overwrite=true');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);

$reply = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

?>

I get a status code of 200 but I’m not seeing the files appear in our file manager. Is the syntax incorrect for the multipart form data? Is this not allowed? Am I doing something else incorrectly?

0 Upvotes
1 Reply 1
jake_marvin_ali
Member

Hubspot API File Manager Upload Issues

I was also having this same problem and spent hours to make it work. I found out that its just a simple syntax in the $params string referencing @Chris_Adams code. The root of the issue is at the last custom boundary string in the code:

It needs to have an additional -- at it’s start to make it work.
So it would need to be changed to this "----custom-boundary-123456789--";
I tried it and it worked for me. Hopefully this can also help others :slight_smile:

I used this gist as reference and compared the codes. Thanks to this :slight_smile:

0 Upvotes