<?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: Accessing get_metadata endpoint without Dropbox Javascript package in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305507#M18427</link>
    <description>&lt;P&gt;Thank You!&amp;nbsp; I see that when I make the body parameter a string and make the other changes concerning Authorization, it works.&amp;nbsp; However I am using the the Access Token that I made manually for my own development purposes.&amp;nbsp; My new problem is about getting the access token on the server side.&amp;nbsp; I'll post another question after I have thought about everything some more.&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@BEEAA17610EBE252DA0E57250B296A61/images/emoticons/1f642.png" alt=":slight_smile:" title=":slight_smile:" /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Oct 2018 23:25:16 GMT</pubDate>
    <dc:creator>milesmajefski</dc:creator>
    <dc:date>2018-10-25T23:25:16Z</dc:date>
    <item>
      <title>Accessing get_metadata endpoint without Dropbox Javascript package</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305437#M18423</link>
      <description>&lt;P&gt;For fun, I'm making a cataloging web app using asp.net core 2.1 MVC and javascript.&amp;nbsp; I don't need a frontend framework, so I don't want to bring in the whole NodeJS npm situation into this project.&amp;nbsp; I'm trying to access&amp;nbsp;&lt;U&gt;&lt;A href="https://api.dropboxapi.com/2/files/get_metadata" target="_blank"&gt;https://api.dropboxapi.com/2/files/get_metadata&lt;/A&gt;&lt;/U&gt; using fetchAPI and Chrome and I am getting this error:&amp;nbsp;&lt;STRONG&gt;'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Their is a similar question on this forum, and the answer was to use the Dropbox Javascript library.&amp;nbsp; I thought this API was like any other restful api where all you needed was to send http requests to endpoints.&amp;nbsp; Is the library required?&lt;/P&gt;&lt;P&gt;Here's all my javascript code.&amp;nbsp; I am using the chooser to get the id of a folder, then I need to make a call to get_metadata to get the path (why doesn't chooser return the path itself? I guess the folder names are too secret.)&lt;/P&gt;&lt;PRE&gt;var options = {

    // Required. Called when a user selects an item in the Chooser.
    success: function (files) {
        //alert("Here's the file link: " + files[0].link);
        console.log('files[0]:', files[0]);
        dbxGetPathFromId(files[0]);
    },

    // Optional. Called when the user closes the dialog without selecting a file
    // and does not include any parameters.
    cancel: function () {
        console.log('Canceled');
    },

    // Optional. "preview" (default) is a preview link to the document for sharing,
    // "direct" is an expiring link to download the contents of the file. For more
    // information about link types, see Link types below.
    //linkType: "preview", // or "direct"

    // Optional. A value of false (default) limits selection to a single file, while
    // true enables multiple file selection.
    multiselect: false, // or true

    // Optional. This is a list of file extensions. If specified, the user will
    // only be able to select files with these extensions. You may also specify
    // file types, such as "video" or "images" in the list. For more information,
    // see File types below. By default, all extensions are allowed.
    extensions: ['.NoEmptyFiles'],

    // Optional. A value of false (default) limits selection to files,
    // while true allows the user to select both folders and files.
    // You cannot specify `linkType: "direct"` when using `folderselect: true`.
    folderselect: true, // or true

    // Optional. A limit on the size of each file that may be selected, in bytes.
    // If specified, the user will only be able to select files with size
    // less than or equal to this limit.
    // For the purposes of this option, folders have size zero.
    sizeLimit: 1, // or any positive number
};

var button = Dropbox.createChooseButton(options);
document.getElementById("dropbox-btn").appendChild(button);

function status(response) {
    if (response.status &amp;gt;= 200 &amp;amp;&amp;amp; response.status &amp;lt; 300) {
        return Promise.resolve(response);
    } else {
        return Promise.reject(new Error(response.statusText));
    }
}

function json(response) {
    return response.json();
}

function dbxGetPathFromId(file) {
    // do an ajax call to dbx api, print the result
    // post to https://api.dropboxapi.com/2/files/get_metadata with auth
    // use json 
    reqData = {
        "path": file.id
    };
    apiURL = 'https://api.dropboxapi.com/2/files/get_metadata';

    fetch(apiURL, {
        method: 'post',
        headers: {
            "Content-type": "application/json; charset=UTF-8"
        },
        body: reqData,
        credentials: 'include'
    })
        .then(json)
        .then(function (data) {
            console.log('Request succeeded with JSON response', data);
        })
        .catch(function (error) {
            console.log('Request failed', error);
        });
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 09:09:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305437#M18423</guid>
      <dc:creator>milesmajefski</dc:creator>
      <dc:date>2019-05-29T09:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing get_metadata endpoint without Dropbox Javascript package</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305445#M18424</link>
      <description>&lt;P&gt;While we&amp;nbsp;recommend using the official libraries, it's not required. You can always call &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation" target="_blank"&gt;the&amp;nbsp;Dropbox API HTTPS endpoints&lt;/A&gt; directly if you prefer. The documentation covers the requirements for each endpoint, and includes an example of calling using curl, e.g., &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata" target="_self"&gt;for&amp;nbsp;/2/files/get_metadata&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;It looks like you're running in to a CORS issue though, due to your use of `credentials: 'include'`.&amp;nbsp;Dropbox API calls, such as for&amp;nbsp;/2/files/get_metadata, are authenticated using&amp;nbsp;Dropbox API access tokens, not the browser's credentials. You need to supply the access token in the "Authorization" header as a "Bearer" token. (Also, the parameters should be a JSON string in the body.)&lt;/P&gt;
&lt;P&gt;So, you code should look more like this:&lt;/P&gt;
&lt;PRE&gt;            fetch(apiURL, {
                method: 'post',
                headers: {
                    "Authorization": "Bearer ACCESS_TOKEN_HERE",
                    "Content-type": "application/json; charset=UTF-8"
                },
                body: JSON.stringify(reqData),
            })&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Oct 2018 18:01:20 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305445#M18424</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-25T18:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing get_metadata endpoint without Dropbox Javascript package</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305507#M18427</link>
      <description>&lt;P&gt;Thank You!&amp;nbsp; I see that when I make the body parameter a string and make the other changes concerning Authorization, it works.&amp;nbsp; However I am using the the Access Token that I made manually for my own development purposes.&amp;nbsp; My new problem is about getting the access token on the server side.&amp;nbsp; I'll post another question after I have thought about everything some more.&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@BEEAA17610EBE252DA0E57250B296A61/images/emoticons/1f642.png" alt=":slight_smile:" title=":slight_smile:" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 23:25:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305507#M18427</guid>
      <dc:creator>milesmajefski</dc:creator>
      <dc:date>2018-10-25T23:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing get_metadata endpoint without Dropbox Javascript package</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305643#M18433</link>
      <description>&lt;P&gt;Great! I'm glad to hear you were able to get that working.&lt;/P&gt;
&lt;P&gt;For information on the OAuth app authorization flow, I&amp;nbsp;recommend reviewing &lt;A href="https://www.dropbox.com/developers/reference/oauth-guide" target="_blank"&gt;the OAuth guide&lt;/A&gt; and &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#authorization" target="_blank"&gt;the authorization documentation&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:07:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Accessing-get-metadata-endpoint-without-Dropbox-Javascript/m-p/305643#M18433</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-26T16:07:51Z</dc:date>
    </item>
  </channel>
</rss>

