APIs & Integrations

Richard_Wein
Membre

Uploading files by API to the file manager

Résolue

Hi. I'm having difficulty with uploading files using the API. I keep getting an error 400 "Bad Request", which doesn't give any more info about what's wrong.

 

I've read the documentation here:

https://developers.hubspot.com/docs/methods/files/post_files

 

And I've read various forum posts like this one:

https://community.hubspot.com/t5/APIs-Integrations/Rest-API-for-File-upload/td-p/280715

 

The trouble is that these all explain how to do it with particular languages, such as Python. I'm using VBA, and what I really need to see is a sample of an actual HTTP request. Here's the HTTP request I'm trying...

 

POST https://api.hubapi.com/filemanager/api/v2/files?hapikey=[redacted]
User-Agent: VBA-Web v4.1.3 (https://github.com/VBA-tools/VBA-Web)
Content-Type: multipart/form-data; boundary=qixbgmtyosycfhj-----------------------------9674769684763
Accept: application/json
Content-Length: 363

--qixbgmtyosycfhj-----------------------------9674769684763
Content-Disposition: form-data; name="files"

VGhlIHF1aWNrIGJyb3duIGZveA0KDQpqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw0KDQo=
--qixbgmtyosycfhj-----------------------------9674769684763
Content-Disposition: form-data; name="file_names"

abc.txt
--qixbgmtyosycfhj-----------------------------9674769684763

I've tried many other permutations too. 

 

By the way, it's not clear whether the file contents need to be encoded in any way. Should non-text files be encoded as Hex64?

0 Votes
1 Solution acceptée
Richard_Wein
Solution
Membre

Uploading files by API to the file manager

Résolue

Thanks @Willson 

 

I'm OK now. I had to install Python, run the Python code recommended by the API documentation, and see exactly what that code was sending in the HTTP request.

 

In case anyone else is interested, here's the HTTP request that's working for me:

POST https://api.hubapi.com/filemanager/api/v2/files?hapikey=[redacted]
User-Agent: VBA-Web v4.1.3 (https://github.com/VBA-tools/VBA-Web)
Content-Type: multipart/form-data; boundary=qixbgmtyosycfhj-----------------------------9674769684763
Accept: application/json
Content-Length: 262

--qixbgmtyosycfhj-----------------------------9674769684763
Content-Disposition: form-data; name="files"; filename="abc.txt"

VGhlIHF1aWNrIGJyb3duIGZveA0KDQpqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw0KDQo=
--qixbgmtyosycfhj-----------------------------9674769684763--

Voir la solution dans l'envoi d'origine

2 Réponses
Willson
HubSpot Employee
HubSpot Employee

Uploading files by API to the file manager

Résolue

Hi @Richard_Wein 

 

I've been reviewing our Forums and was able to find a conversation around this that may assist with an example of a HTTP request, take a look here:
https://community.hubspot.com/t5/APIs-Integrations/Rest-API-for-File-upload/m-p/280715

 

To answer your point on the encoding, there's no decoding that goes on in the File Manager itself, so you would need to do the conversion and send the file in the desired format.

 

I hope this helps!

Product Manager @ HubSpot
0 Votes
Richard_Wein
Solution
Membre

Uploading files by API to the file manager

Résolue

Thanks @Willson 

 

I'm OK now. I had to install Python, run the Python code recommended by the API documentation, and see exactly what that code was sending in the HTTP request.

 

In case anyone else is interested, here's the HTTP request that's working for me:

POST https://api.hubapi.com/filemanager/api/v2/files?hapikey=[redacted]
User-Agent: VBA-Web v4.1.3 (https://github.com/VBA-tools/VBA-Web)
Content-Type: multipart/form-data; boundary=qixbgmtyosycfhj-----------------------------9674769684763
Accept: application/json
Content-Length: 262

--qixbgmtyosycfhj-----------------------------9674769684763
Content-Disposition: form-data; name="files"; filename="abc.txt"

VGhlIHF1aWNrIGJyb3duIGZveA0KDQpqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw0KDQo=
--qixbgmtyosycfhj-----------------------------9674769684763--