1
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?

2
  • What isn't working exactly? What response do you get? Commented Oct 13, 2017 at 18:48
  • I am getting a has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource Commented Jul 31, 2020 at 13:11

1 Answer 1

1

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"}));
Sign up to request clarification or add additional context in comments.

1 Comment

I am getting a has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.