FileUpload Example Postman

Hello,

can anyone please provide a working example for a file upload. Trying few things but ending at the moment with error:

OliSteini_0-1729000307277.png

@OliSteini - I’ve worked with this a number of time and I agree the documentation and examples are a bit underwhelming.

My approch has ended up being around getting the file data into an array format and then using that as the file parameter to the HubSpot API call. This is sensetive to the encoding used and it also seems necessary to be very careful constructing the header for the request.

 # try this as a string input to files API call
 upload_url = "https://api.hubapi.com/filemanager/api/v3/files/upload"
 folder_name ="/test"
 file_options = {
 'ttl' : None,
 'access': 'PUBLIC_NOT_INDEXABLE',
 'overwrite': True,
 'duplicateValidationStrategy': 'NONE',
 'duplicateValidationScope': 'EXACT_FOLDER'
 }
 files_data = {
 'fileName' : file_name,
 'folderPath' : folder_name,
 'file': file_string,
 'options': json.dumps(file_options)
 }
 file_headers = {
 'Authorization': 'Bearer ' + appToken
 }

 #note special request headers required for file API payload encoding
 response = requests.post(upload_url, files=files_data, headers=file_headers)
 print("Doc upload response: ", response.status_code)

I hope this is helpful.

Steve

try again hopefully it will soved.