We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
notstrom
3 years agoHelpful | Level 6
Delete a Folder programmatically
How can I write a programm to delete a folder in my dropbox. There are all permissions set. The accesstoken is ok. I'm able to create a folders in my code.
Unfortunately deleting a folder results in a 'bad request'. My folder structure is
Main/
....2023/
....2024/
Here is the code segment:
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
HttpResponseMessage response = await httpClient.PostAsync("https://api.dropboxapi.com/2/files/get_metadata",
new StringContent($"{{\"path\": \"{filePath}\"}}"));
if (response.IsSuccessStatusCode)
The variable response contains:
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Content-Security-Policy: sandbox allow-forms allow-scripts
X-Content-Type-Options: nosniff
Accept-Encoding: identity,gzip
Vary: Accept-Encoding
X-Dropbox-Response-Origin: far_remote
X-Dropbox-Request-Id: 75a037a2e8b24097b5188d266d6b9b71
Cache-Control: no-cache
Date: Wed, 20 Sep 2023 10:11:08 GMT
Server: envoy
Content-Length: 226
Content-Type: text/plain; charset=utf-8
}}
I hope you can help me.
best regards
Peter
1 Reply
- Greg-DB3 years ago
Dropbox Community Moderator
The code you shared calls /2/files/get_metadata, which retrieves metadata for a file or folder, but if you want to delete something, you should instead call /2/files/delete_v2 (or /2/files/delete_batch to delete multiple items).
In any case, to debug a 400 error like this, print out the response body. It should contain a more useful error message.
About Discuss Dropbox Developer & API
Make connections with 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!