APIs & Integrations

jeanRoger
Member

upload file to file manager hubspot api error axios

SOLVE

keep getting an error while trying to upload a file to hubspot using axios ,

[Error: Error: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 400 Bad Request</title>
</head>
<body><h2>HTTP ERROR 400</h2>
<p>Problem accessing /filemanager/api/v3/files/upload. Reason:
<pre> Bad Request</pre></p>
</body>
</html>

 

tried in postman and its working, my body looks like

const fileOptions = {
access: 'PUBLIC_INDEXABLE',
overwrite: false,
duplicateValidationStrategy: 'NONE',
duplicateValidationScope: 'ENTIRE_PORTAL',
};
const fileParams = {
options: JSON.stringify(fileOptions),
folderPath: 'bills',
};
const body = new FormData();
body.append('file', fs.createReadStream('atest.pdf'));
Object.keys(fileParams).forEach((key) => body.append(key, fileParams[key]));
0 Upvotes
1 Accepted solution
jeanRoger
Solution
Member

upload file to file manager hubspot api error axios

SOLVE

Found the solution... it was because my space didn't have access to the filemanager options, after trying with a developer account, I was able to make it work

View solution in original post

0 Upvotes
8 Replies 8
Arbi
Member

upload file to file manager hubspot api error axios

SOLVE

hey @jeanRoger ,

do you know how this works in Wix, in my case i need to use this API to upload files from Wix form, but unfortunately it won't work for me,

this is my code:

  const fileOptions = {
    access: 'PUBLIC_INDEXABLE',
    overwrite: false,
    duplicateValidationStrategy: 'NONE',
    duplicateValidationScope: 'ENTIRE_PORTAL',
  };
  const fileParams = {
    options: JSON.stringify(fileOptions),
    folderPath: 'docs',
  };
  const form = new FormData();
  form.append('file',fs.createReadStream(filepath));
  Object.keys(fileParams).forEach((key) => form.append(key, fileParams[key]));
  console.log('body', form);
  
  let otp = {
     method: "POST",
     headers:{
       'Content-Type': "multipart/form-data",
       'Authorization': `Bearer ${'token'}`,
    },
     body: JSON.stringify(form),
     mode: 'cors',
     cache: 'no-cache',
 };
  return fetch(manageUrl, otp)
  .then((httpResponse)=>{
      if(httpResponse.ok){
          return httpResponse.json();
      }else{
          console.log('httpresponse', httpResponse.statusText);
          return Promise.reject("Fetch did not succeed");
      }
    });
 
and this is the payload:
{"_overheadLength":405,"_valueLength":131,"_valuesToMeasure":[{"_readableState":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":false,"ended":false,"endEmitted":false,"reading":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":false,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"decoder":null,"encoding":null},"_events":{},"_eventsCount":3,"path":"https://static.wixstatic.com/media/d8ba6f_22f6d87e2552480e869467d6cfb663c5~mv2.jpeg","fd":null,"flags":"r","mode":438,"end":null,"autoClose":true,"bytesRead":0,"closed":false}],"writable":false,"readable":true,"dataSize":0,"maxDataSize":2097152,"pauseStreams":true,"_released":false,"_streams":["----------------------------048251601101966565341975\r\nContent-Disposition: form-data; name=\"file\"; filename=\"d8ba6f_22f6d87e2552480e869467d6cfb663c5~mv2.jpeg\"\r\nContent-Type: image/jpeg\r\n\r\n",{"source":{"_readableState":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":false,"ended":false,"endEmitted":false,"reading":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":false,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"decoder":null,"encoding":null},"_events":{},"_eventsCount":3,"path":"https://static.wixstatic.com/media/d8ba6f_22f6d87e2552480e869467d6cfb663c5~mv2.jpeg","fd":null,"flags":"r","mode":438,"end":null,"autoClose":true,"bytesRead":0,"closed":false},"dataSize":0,"maxDataSize":null,"pauseStream":true,"_maxDataSizeExceeded":false,"_released":false,"_bufferedEvents":[{"0":"pause"}],"_events":{},"_eventsCount":1},null,"----------------------------048251601101966565341975\r\nContent-Disposition: form-data; name=\"options\"\r\n\r\n","{\"access\":\"PUBLIC_INDEXABLE\",\"overwrite\":false,\"duplicateValidationStrategy\":\"NONE\",\"duplicateValidationScope\":\"ENTIRE_PORTAL\"}",null,"----------------------------048251601101966565341975\r\nContent-Disposition: form-data; name=\"folderPath\"\r\n\r\n","docs",null],"_currentStream":null,"_insideLoop":false,"_pendingNext":false,"_boundary":"--------------------------048251601101966565341975"}
 
anyone can help me to solve this?
thanks!
Rajkumars
Member

upload file to file manager hubspot api error axios

SOLVE

Hello jeanRoger,

            I am trying to upload a file to the Hubspot file manager using java,  can you please share java code?

0 Upvotes
jeanRoger
Solution
Member

upload file to file manager hubspot api error axios

SOLVE

Found the solution... it was because my space didn't have access to the filemanager options, after trying with a developer account, I was able to make it work

0 Upvotes
Sheamus
Participant

upload file to file manager hubspot api error axios

SOLVE

This should be filed as a bug with Hubspot.  400 is a bad request. 401 is unauthorized which makes way more sense in this case.

0 Upvotes
selvaadharva
Participant

upload file to file manager hubspot api error axios

SOLVE

Hello jeanRoger,

           Even I am trying to upload a file to the Hubspot file manager, but I am not able to upload using postman can you please share your postman  URL and body

0 Upvotes
jeanRoger
Member

upload file to file manager hubspot api error axios

SOLVE

Hello @selvaadharva , on postman you have to use formData, so it has to be something like this:

Screen Shot 2020-12-14 at 9.40.58 AM.png

Note: for the file, use the type file 

and for the options object, something like this : 

{"access":"PUBLIC_INDEXABLE","ttl":"P3M","overwrite":false,"duplicateValidationStrategy":"NONE","duplicateValidationScope":"ENTIRE_PORTAL"}
selvaadharva
Participant

upload file to file manager hubspot api error axios

SOLVE

Thanks a lot!. It's worked for me...

quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

upload file to file manager hubspot api error axios

SOLVE

Hi @jeanRoger 

Can you post a screenshot of your api log, give us the request body and the response body

 

hsSign_smaller.png


0 Upvotes