Prateek Agarwal
Prateek Agarwal

Reputation: 20

Dropbox list_folder api javascript not working

var xhr = new XMLHttpRequest();
xhr.responseType = 'String';
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4 && xhr.status === 200) {
    var response = xhr.response;
    console.log(response);
  }
};
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
  path: '/lol'
}));
xhr.send();

I can't figure out what seems wrong in the code. Any Help?

Upvotes: 1

Views: 209

Answers (1)

Andrew L
Andrew L

Reputation: 5496

Looking at documentation for list_folder - that endpoint is a RPC endpoint:

These endpoints accept arguments as JSON in the request body and return results as JSON in the response body. RPC endpoints are on the api.dropboxapi.com domain.

Dropbox-API-Arg header seems to be used for Content-upload and Content-download type endpoints

I do not see anything about a header called Dropbox-API-Arg needed for /files/list_folder endpoint. Try something like

xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({path:"/lol"}));

Upvotes: 1

Related Questions