Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Tamas B.
10 years agoNew member | Level 1
Dropbox Business API 'bad request' error
Hi Team,
we are using the Dropbox REST API with OAuth2.
When attempting to get list of groups we are receiving an 'Error 400 bad request' error.
Below is the sample code written in C#:
var webRequest = (HttpWebRequest)WebRequest.Create("https://api.dropbox.com/1/team/groups/list");
webRequest.Method = "POST";
webRequest.Accept = "application/json";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60";
webRequest.ContentType = "application/json";
webRequest.Headers.Add("Authorization: Bearer <accesToken>");
string postData = JsonConvert.SerializeObject(bodyContent);
byte[] bytes = new byte[postData.Length * sizeof(char)];
System.Buffer.BlockCopy(postData.ToCharArray(), 0, bytes, 0, bytes.Length);
webRequest.ContentLength = bytes.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(bytes, 0, bytes.Length);
dataStream.Close();
var webResponse = (HttpWebResponse)webRequest.GetResponse();
Any suggestion on how to fix this error ?
Thank you
9 Replies
Replies have been turned off for this discussion
- Steve M.10 years ago
Dropbox Staff
What's the content of the response from the server? There should be an error message explaining what the issue is.
(Or perhaps you can share what's in
bodyContentso we can guess as to the issue.) - Steve M.10 years ago
Dropbox Staff
BTW, this code is untested, but I think you can simplify to this:
var webRequest = (HttpWebRequest)WebRequest.Create("https://api.dropbox.com/1/team/groups/list"); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; webRequest.Headers.Add("Authorization: Bearer <accesToken>"); using (var streamWriter = new StreamWriter(webRequest.GetRequestStream())) { streamWriter.Write(JsonConvert.SerializeObject(bodyContent)); } var webResponse = (HttpWebResponse)webRequest.GetResponse();FYI, in the case of
/groups/list, the JSON body should just be{}, since this method doesn't take any parameters. - Tamas B.10 years agoNew member | Level 1
Thank you for your response,
the 'bodyContent' variable contains an empty JSON dictionary ( {} ).
The error details state the following:
Status: Protocol Error
Status Code: Bad Request - Steve M.10 years ago
Dropbox Staff
What's the actual body of the error response, though? The HTTP response should contain a body with details.
- Steve M.10 years ago
Dropbox Staff
FYI, I ran my version of the code (with
var bodyContent = new { };), and it succeeds. If yours is still failing, we'll really need to see the response body. - Tamas B.10 years agoNew member | Level 1
The HTTP response contains an empty body (content length = -1 )
- Tamas B.10 years agoNew member | Level 1
The issue have been resolved. Turns out the problem was caused by the string which was returned by the method call 'JsonConvert.SerializeObject()'.
Thank you for your help
- Steve M.10 years ago
Dropbox Staff
Out of curiosity, in case it happens to someone else in the future, what was the issue with the string that came back from
JsonConvert.SerializeObject? - Tamas B.10 years agoNew member | Level 1
The function returned the following string: "{ }"
the request failed on the additional quote marks
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!