<?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: CORS Error HTTP API using Ajax in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/CORS-Error-HTTP-API-using-Ajax/m-p/415398#M22402</link>
    <description>&lt;P&gt;Is that the actual code you ran to produce that particular error? The error mentions the 'dl.dropboxusercontent.com' hostname, which is a real&amp;nbsp;Dropbox hostname, but isn't what you should be using for this API call, and isn't used in your supplied code anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, for the code you shared, it looks like there are two issues:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You're supplying your API call parameters as a JSON string in a 'data' header. The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create" target="_self"&gt;/2/file_requests/create endpoint&lt;/A&gt; is an &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"RPC"-style&lt;/A&gt; endpoint though, so it expects the API call parameters as a JSON string in the request body, not a header.&lt;/LI&gt;
&lt;LI&gt;You're supplying a destination path of "/", but that should be a path to a particular folder.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, your code should look more like this:&lt;/P&gt;
&lt;PRE&gt;const title = "more_examples.txt";
const destination = "/some folder";

const response = $.ajax({
    url: "https://api.dropboxapi.com/2/file_requests/create",
            type: "POST",
            async: false,
            headers: {
                    "Authorization": "Bearer &amp;lt;token&amp;gt;",
                    "Content-Type": "application/json",
            },
            "data": '{"title": "' + title + '","destination": "' + destination + '","deadline": {"deadline": "2020-10-12T17:00:00Z","allow_late_uploads": "seven_days"}, "open": true}'
    });&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Apr 2020 17:27:55 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2020-04-29T17:27:55Z</dc:date>
    <item>
      <title>CORS Error HTTP API using Ajax</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/CORS-Error-HTTP-API-using-Ajax/m-p/415113#M22398</link>
      <description>&lt;P&gt;So I'm new to the Dropbox API and I've been experimenting with HTTP API calls using javascript's Ajax function. I'm currently trying to use the /create functionality but I'm encountering a CORS error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the code I'm using:&lt;/P&gt;
&lt;PRE&gt;const title = "more_examples.txt";
	const destination = "/";

	const response = $.ajax({
		url: "https://api.dropboxapi.com/2/file_requests/create",&lt;BR /&gt;                type: "POST",&lt;BR /&gt;                dataType: 'application/octet-stream', &lt;BR /&gt;                async: false, &lt;BR /&gt;                headers: { &lt;BR /&gt;                        "Authorization": "Bearer &amp;lt;TOKEN&amp;gt;", &lt;BR /&gt;                        "Content-Type": "application/json", &lt;BR /&gt;                        "data": '{"title": "' + title + '","destination": "' + destination + '","deadline": {"deadline": "2020-10-12T17:00:00Z","allow_late_uploads": "seven_days"},&lt;BR /&gt;                        "open": true}'&lt;BR /&gt;                }&lt;BR /&gt;        });&lt;/PRE&gt;
&lt;P&gt;And here's the error:&lt;/P&gt;
&lt;PRE&gt;Cross-Origin Request Blocked: The Same Origin Policy disallows&lt;BR /&gt;reading the remote resource at https://dl.dropboxusercontent.com/2/file_requests/create.&lt;BR /&gt;(Reason: CORS request did not succeed).&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make matters worse, I had previously tried downloading a file and that totally worked! Here's that code too:&lt;/P&gt;
&lt;PRE&gt;        const path = "example.txt";&lt;BR /&gt;
	const args = {
		"path": path
	};

	const response = $.ajax({
		url: "https://content.dropboxapi.com/2/files/download",
		type: "POST",
		dataType: 'application/octet-stream',
		async: false,
		headers: {
			"Authorization": "Bearer &amp;lt;TOKEN&amp;gt;",
			"Dropbox-API-Arg": '{"path": "/example.txt"}'
		}
	});&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas about where I went wrong? I want to keep to the HTTP API rather than the python or Node one, so I'd really appreciate any advice here. I'm not sure what went wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 07:56:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/CORS-Error-HTTP-API-using-Ajax/m-p/415113#M22398</guid>
      <dc:creator>PoisonIvy</dc:creator>
      <dc:date>2020-04-29T07:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error HTTP API using Ajax</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/CORS-Error-HTTP-API-using-Ajax/m-p/415398#M22402</link>
      <description>&lt;P&gt;Is that the actual code you ran to produce that particular error? The error mentions the 'dl.dropboxusercontent.com' hostname, which is a real&amp;nbsp;Dropbox hostname, but isn't what you should be using for this API call, and isn't used in your supplied code anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, for the code you shared, it looks like there are two issues:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You're supplying your API call parameters as a JSON string in a 'data' header. The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create" target="_self"&gt;/2/file_requests/create endpoint&lt;/A&gt; is an &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"RPC"-style&lt;/A&gt; endpoint though, so it expects the API call parameters as a JSON string in the request body, not a header.&lt;/LI&gt;
&lt;LI&gt;You're supplying a destination path of "/", but that should be a path to a particular folder.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, your code should look more like this:&lt;/P&gt;
&lt;PRE&gt;const title = "more_examples.txt";
const destination = "/some folder";

const response = $.ajax({
    url: "https://api.dropboxapi.com/2/file_requests/create",
            type: "POST",
            async: false,
            headers: {
                    "Authorization": "Bearer &amp;lt;token&amp;gt;",
                    "Content-Type": "application/json",
            },
            "data": '{"title": "' + title + '","destination": "' + destination + '","deadline": {"deadline": "2020-10-12T17:00:00Z","allow_late_uploads": "seven_days"}, "open": true}'
    });&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 17:27:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/CORS-Error-HTTP-API-using-Ajax/m-p/415398#M22402</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-04-29T17:27:55Z</dc:date>
    </item>
  </channel>
</rss>

