APIs & Integrations

ArnaudOni
Member

Upload file with V3 API (ruby) Bad Request

Hello there,

I am trying to upload a file with the POST v3 api endpoint in my Ruby project. This is my code:

 

 

 

 require 'net/http'
    require 'json'

    uri = URI.parse('https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=myKey')

    data = {
      file: File.new('my_file.pdf'),
      folderId: '43313988041',
      option: {
          access: 'PUBLIC_INDEXABLE',
          ttl: 'P3M',
          overwrite: false,
          duplicateValidationStrategy: 'NONE',
          duplicateValidationScoe: 'ENTIRE_PORTAL'
      }
    }

    response = Net::HTTP.post(uri, JSON.generate(data), {'Content-Type': 'multipart/form-data'} )
    puts response.body

 

 

 

 

I recive this response body:

 

 

 

<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>

 

 

 

 

My apiKey and my folderId are ok. I don't know what I am doing wrong. 

Thank you so much if you could help me 🙂

0 Upvotes
3 Replies 3
ArnaudOni
Member

Upload file with V3 API (ruby) Bad Request

Hi there,

My goal is to attach my new doc just created with a contact which I have to create too. Si just to know if the steps are good.

1) ulpoad the file with V3 

2) create contact with the file_id recived in the response

 

The point is, can I create this associtaion in the create contact request. I dont see association proprety in the Creat Contact endpoint. So if it's not possible how I am suppose to manage that ?

 

1) upload file

2) create contact

3) create association ?

 

Thank you for your help 🙂 @dennisedson@altjx and @GaryElliott

0 Upvotes
ArnaudOni
Member

Upload file with V3 API (ruby) Bad Request

Hello @dennisedson,

Thank you for your help, it's working better with http gem than net http ^^'
Just few questions:

- My new file was uploaded in the 'marketing' part but I thougth it will be uploaded in the 'sales' part because I want to associate this file with a deal. Is it an issue ?
- In my new request I send in the option an ID corresponding at the deal I want to attach with this new uploaded file.

    file_options = {
        "access" => "PUBLIC_INDEXABLE",
        "ttl" => "P3M",
        "overwrite" => false,
        "duplicateValidationStrategy" => "NONE",
        "duplicateValidationScope" => "ENTIRE_PORTAL",
        "deal_id": '111111'
    }

But in my response of the upload I don't have this information coming back to create the attachement.

What is the best way to send the deal_id in my POST upload file ?

 

Thank you so much for your help.

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Upload file with V3 API (ruby) Bad Request

@ArnaudOni 

I am not a ruby developer so apologies if this is of no help, but have you looked at the ruby example here

@altjx and @GaryElliott are actual smart ruby folks unlike me.  Hopefully they are more helpful 😀

0 Upvotes