<?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: Download a file via API using PHP and cURL in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610412#M28242</link>
    <description>&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have run the php file locally (XAMP) and it runs with no issues at all, so something on the server seems to be causing the issue, so I am now investigating this and I will update when/if I have more information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2022 21:06:18 GMT</pubDate>
    <dc:creator>dghatch</dc:creator>
    <dc:date>2022-07-18T21:06:18Z</dc:date>
    <item>
      <title>Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/609838#M28221</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to download a file from my dropbox app, I have tried the cURL code in postman it works with no issues:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-download" target="_blank" rel="noopener"&gt;https://www.dropbox.com/developers/documentation/http/documentation#files-download&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have created the cURL as php and am running it on my server, but it doesn't work, I keep getting the "cat" returned to me.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Authorization: Bearer ' . $token;
$headers[] = 'Dropbox-API-Arg: {"path":"' . $in_filepath . '"}';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
curl_close($ch);

var_dump ($result);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-07-15 153445.png" style="width: 715px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/30366i36BEDF70A5AB64A2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-07-15 153445.png" alt="Screenshot 2022-07-15 153445.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas what I have done wrong?&lt;/P&gt;
&lt;P&gt;Thanks for your time.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 14:39:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/609838#M28221</guid>
      <dc:creator>dghatch</dc:creator>
      <dc:date>2022-07-15T14:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/609920#M28223</link>
      <description>&lt;P&gt;I tried a snippet nearly identical to yours on php&amp;nbsp;&lt;SPAN class="s1"&gt;7.4.28 and it worked for me, though php seemed to like me setting the content type &amp;amp; accept headers as&amp;nbsp; well:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;$headers[] = "Content-Type: application/octet-stream";&lt;BR /&gt;$headers[] = "Accept: application/octet-stream";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;I'm not 100% sure what the error is from just the image. I'd recommend trying to print out the response headers for additional information. The response code, along with the value of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;Dropbox-Api-Result in content endpoints can help diagnose.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 21:35:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/609920#M28223</guid>
      <dc:creator>kylea</dc:creator>
      <dc:date>2022-07-15T21:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610231#M28232</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1006906"&gt;@kylea&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using php 7.4 and 8, and I have printed the requestHeaders, but I am still getting the cat error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;" array(11) { ["Host"]=&amp;gt; string(25) "www.host.com" ["Te"]=&amp;gt; string(8) "trailers" ["Sec-Fetch-User"]=&amp;gt; string(2) "?1" ["Sec-Fetch-Site"]=&amp;gt; string(4) "none" ["Sec-Fetch-Mode"]=&amp;gt; string(8) "navigate" ["Sec-Fetch-Dest"]=&amp;gt; string(8) "document" ["Upgrade-Insecure-Requests"]=&amp;gt; string(1) "1" ["Accept-Encoding"]=&amp;gt; string(17) "gzip, deflate, br" ["Accept-Language"]=&amp;gt; string(14) "en-GB,en;q=0.5" ["Accept"]=&amp;gt; string(85) "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" ["User-Agent"]=&amp;gt; string(80) "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0" } &lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 18 Jul 2022 11:49:04 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610231#M28232</guid>
      <dc:creator>dghatch</dc:creator>
      <dc:date>2022-07-18T11:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610309#M28237</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1557130"&gt;@dghatch&lt;/a&gt; My colleague was asking about the response headers, but it looks like you've printed out the request headers here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, I've also tried the code you shared here, plugging in my own access token and path, and as long as I fix the "Content-Type" as my colleague mentioned, it does work for me. (I am using PHP 7.4.29.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen calls fail like this when the HTTP request itself has been malformed though, so make sure your request doesn't contain any invalid data. For example, make sure your $token and $in_filepath values don't contain any extra whitespace, etc.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 16:00:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610309#M28237</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-07-18T16:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610336#M28240</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt; and &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1006906"&gt;@kylea&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I have done it right this time (response headers this time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;    HTTP/1.1 400 Bad Request
    Content-Length: 14468
    Content-Type: text/html
    Vary: Accept-Encoding
    X-Dropbox-Response-Origin: local
    Date: Mon, 18 Jul 2022 17:11:48 GMT
    Server: envoy
    Connection: close

string(14672) "HTTP/1.1 400 Bad Request Content-Length: 14468 Content-Type: text/html Vary: Accept-Encoding X-Dropbox-Response-Origin: local Date: Mon, 18 Jul 2022 17:11:48 GMT Server: envoy Connection: close &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm starting to think it's something else, not code. &amp;nbsp; I have tried adding a random token and I get the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 17:17:08 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610336#M28240</guid>
      <dc:creator>dghatch</dc:creator>
      <dc:date>2022-07-18T17:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610361#M28241</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1557130"&gt;@dghatch&lt;/a&gt; Thanks! It does seem like the request is getting malformed somehow. Have you inspected the exact values you're sending to &lt;A href="https://content.dropboxapi.com/2/files/download?" target="_blank"&gt;https://content.dropboxapi.com/2/files/download&lt;/A&gt;? Make sure there's no extraneous data, in both the $token and $in_filepath values, as that could mangle the request, resulting in the generic error response.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 18:12:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610361#M28241</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-07-18T18:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610412#M28242</link>
      <description>&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have run the php file locally (XAMP) and it runs with no issues at all, so something on the server seems to be causing the issue, so I am now investigating this and I will update when/if I have more information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 21:06:18 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610412#M28242</guid>
      <dc:creator>dghatch</dc:creator>
      <dc:date>2022-07-18T21:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Download a file via API using PHP and cURL</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610532#M28245</link>
      <description>&lt;P&gt;I have now solved the issue, it turns out that the server (runing with DirectAdmin) was using an old version of curl (7.24.0) and when this was updated to 7.84.0 the problems was fixed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for all your help.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 10:57:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-a-file-via-API-using-PHP-and-cURL/m-p/610532#M28245</guid>
      <dc:creator>dghatch</dc:creator>
      <dc:date>2022-07-19T10:57:41Z</dc:date>
    </item>
  </channel>
</rss>

