APIs & Integrations

Not applicable

How to upload file via javascript request

Hi, I've read through the API for uploading to filemanager using Python, I'm now trying to use the API to upload a PDF to the filemanager via netsuite using their Javascript API.

I the netsuite API sends a post request but only uses 3 parameters : API Url, headers and Body

I have the API url and set to the endpoint with the hAPIkey generated :
'api.hubapi.com/filemanager/api/v2/files?hapikey=xxxxxxxxxxxxxxxxxx'

For the body i set it to the multipart/form-data and the multi-part form encoded PDF.
However we dont have a data parameter so im not sure where to set the data and the folder paths :

data={
        "folder_paths": "folder-in-the-cos-file-manager/subfolder"
         }

when I try to send out the post request it just returns an response code 406 with no message

{
   type: "http.ClientResponse",
   code: 406,
   headers: {
      "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
      Server: "cloudflare",
      "CF-RAY": "49aff0f6b937a6dd-DUB",
      "Access-Control-Allow-Credentials": "false",
      "Set-Cookie": "__cfduid=d6c3edc2ea00fe02ce37cc28a07eaac071547802760; expires=Sat, 18-Jan-20 09:12:40 GMT; path=/; domain=.hubapi.com; HttpOnly",
      "Content-Length": "0",
      Date: "Fri, 18 Jan 2019 09:12:40 GMT",
      "Expect-CT": "max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"",
      Via: "1.1 mono001.prod.dub.netledger.com"
   },
   body: ""
}

any assistance is appreciated on how to proceed with a successful upload

Thanks!

0 Upvotes
1 Reply 1
cbarley
HubSpot Alumni
HubSpot Alumni

How to upload file via javascript request

Hi @wesley.lim11, that error looks like it's coming from Cloudflare so I can't be certain what it means. That said, have you tried using code snippets in Postman: https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/? I'd try making a simple request with a form upload field by changing the value of the form field to a type of file:

Then having the Code snippet get generated for you based off of the successful request.

0 Upvotes