<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can´t get file upload via file API to work - please help! in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426850#M42410</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/2450"&gt;@tjoyce&lt;/a&gt; , do you see any offenders in this code block?&lt;/P&gt;</description>
    <pubDate>Mon, 12 Apr 2021 13:26:42 GMT</pubDate>
    <dc:creator>dennisedson</dc:creator>
    <dc:date>2021-04-12T13:26:42Z</dc:date>
    <item>
      <title>Can´t get file upload via file API to work - please help!</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426609#M42392</link>
      <description>&lt;P&gt;Hi fellow Hubspotters,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;for some reason we can not get the file API to work.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What we try to do is upload a file via the API using php code, but we keep getting errors or the file we try to upload via API never makes it to the /docs folder.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;We use this stable version as per API documentation:&lt;BR /&gt;&lt;A href="https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file?_ga=2.62397156.993641842.1617968706-43190547.1588054962" target="_blank" rel="noopener"&gt;https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file?_ga=2.62397156.993641842.1617968706-43190547.1588054962&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And this is the code we use (API key shortened here) - the code is currently only sitting in a snippet which is run when loading a page:&lt;BR /&gt;&lt;BR /&gt;&amp;lt;?php&lt;/P&gt;
&lt;P&gt;// This example uploads a local file named 'example_file.txt'&lt;BR /&gt;// to the /docs folder, without checking for duplicate files&lt;/P&gt;
&lt;P&gt;$post_url = "&lt;A href="https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=6e8555a3-9090-4fed-82d2-7112d1xxx" target="_blank" rel="noopener"&gt;https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=&lt;/A&gt;xxx";&lt;/P&gt;
&lt;P&gt;$upload_file = new CURLFile('&lt;A href="https://b2rmsw8i.myraidbox.de/wp-content/uploads/2021/04/EP-TEST_1217.pdf','application/octet-stream" target="_blank" rel="noopener"&gt;https://b2rmsw8i.myraidbox.de/wp-content/uploads/2021/04/EP-TEST_1217.pdf','application/octet-stream&lt;/A&gt;');&lt;BR /&gt;&lt;BR /&gt;$file_options = array(&lt;BR /&gt;"access" =&amp;gt; "PUBLIC_INDEXABLE",&lt;BR /&gt;"ttl" =&amp;gt; "P3M",&lt;BR /&gt;"overwrite" =&amp;gt; false,&lt;BR /&gt;"duplicateValidationStrategy" =&amp;gt; "NONE",&lt;BR /&gt;"duplicateValidationScope" =&amp;gt; "ENTIRE_PORTAL"&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;$post_data = array(&lt;BR /&gt;"file" =&amp;gt; $upload_file,&lt;BR /&gt;"options" =&amp;gt; json_encode($file_options),&lt;BR /&gt;"folderPath" =&amp;gt; "/docs"&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;$ch = curl_init();&lt;BR /&gt;@curl_setopt($ch, CURLOPT_POST, true);&lt;BR /&gt;@curl_setopt($ch, CURLOPT_URL, $post_url);&lt;BR /&gt;@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);&lt;/P&gt;
&lt;P&gt;$response = @curl_exec($ch); //Log the response from HubSpot as needed.&lt;BR /&gt;$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code&lt;BR /&gt;@curl_close($ch);&lt;BR /&gt;echo $status_code . " " . $response;&lt;BR /&gt;?&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Any idea what the problem is?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help! Really appreciate it.&lt;BR /&gt;Best Lutz&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 13:25:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426609#M42392</guid>
      <dc:creator>Effecticore</dc:creator>
      <dc:date>2021-04-12T13:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can´t get file upload via file API to work - please help!</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426850#M42410</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/2450"&gt;@tjoyce&lt;/a&gt; , do you see any offenders in this code block?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 13:26:42 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426850#M42410</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-04-12T13:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can´t get file upload via file API to work - please help!</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426872#M42413</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/92022"&gt;@Effecticore&lt;/a&gt;&amp;nbsp;- Your main offender is the URL.. should be&amp;nbsp;&lt;A href="https://api.hubapi.com/files/v3/files" target="_blank"&gt;https://api.hubapi.com/files/v3/files&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a sample code taken right out of my own app, so I know it works &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Unfortunately, it's using the OAuth token flow, but I think this will give you enough to go from&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$post_url = "https://api.hubapi.com/files/v3/files";

      $upload_file = new \CURLFile($request-&amp;gt;file('files')-&amp;gt;getPathName(),'application/octet-stream', $request-&amp;gt;file('files')-&amp;gt;getClientOriginalName());

      $file_options = array(
          "access" =&amp;gt; "PUBLIC_INDEXABLE",
          "overwrite" =&amp;gt; false,
      );

      $post_data = array(
          "file" =&amp;gt; $upload_file,
          "options" =&amp;gt; json_encode($file_options),
          "folderPath" =&amp;gt; "belch.io/uploads"
      );

      $authorization = "Authorization: Bearer " . $request-&amp;gt;header('Token');


      $ch = curl_init();
      @curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization ));
      @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      @curl_setopt($ch, CURLOPT_POST, true);
      @curl_setopt($ch, CURLOPT_URL, $post_url);
      @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

      $response    = @curl_exec($ch);
      $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 
      @curl_close($ch);
      //echo $status_code . " " . $response;

      $res = json_decode($response, true);
      $res['friendly_url'] = $res['url'];
      $return = [
        'objects' =&amp;gt; [
          $res
        ]
      ];
      //$file = json_decode($response, true);
      return response()-&amp;gt;json($return);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 13:56:39 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426872#M42413</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2021-04-12T13:56:39Z</dc:date>
    </item>
  </channel>
</rss>

