We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
suihakei
6 years agoExplorer | Level 3
I want to upload files to Dropbox Business using the Dropbox API
# Summary
I used the "/2/files/upload" endpoint of the Dropbox API.
However, the file is uploaded to your personal folder.
I want to upload files to the team folder using the API.
# Tried
I found the following questions.
It says "Use Dropbox-API-Path-Root".
The Dropbox-API-Path-Root requires Namespace.
So I used Dropbox API Explorer • namespaces/list to find the Namespace of the folder I wanted to upload.
I found the desired value in the data returned by Dropbox API Explorer.
{
"name": "FOLDER_NAME",
"namespace_id": "xxxxxxxxxx",
"namespace_type": {
".tag": "shared_folder"
}
},
So I added the following code to PHP's program processing.
This is written in the header section of Guzzle.
$header = [
'Authorization' => 'Bearer ' . ACCESS_TOKEN,
'Content-Type' => 'application/octet-stream',
'Dropbox-API-Path-Root' => json_encode([
'.tag' => 'shared_folder',
'shared_folder' => 'namespace_id(xxxxxxxxxx)'
]),
'Dropbox-API-Arg' => json_encode([
'path' => '/example/upload/',
'mode' => 'add',
'autorename' => true,
'mute' => false,
'strict_conflict' => false,
]),
];
However, I get a ".tag shared_folder does not exist" error.
There was an error when I changed to '.tag' => 'root'.
Why is this?
Please tell me how to do it.
Thank you.
3 Replies
- Greg-DB6 years ago
Dropbox Community Moderator
The 'Dropbox-API-Path-Root' header does not support a 'shared_folder' option. Please refer to the Namespace Guide for information and examples on how to use the header, such as what options it supports:
https://www.dropbox.com/developers/reference/namespace-guide
For example, it sounds like you probably want to use the 'namespace_id' option.
- suihakei6 years agoExplorer | Level 3
Thank you for your reply.
As you explained, I set it as follows.
'Dropbox-API-Path-Root' => json_encode([ '.tag' => 'namespace_id', 'namespace_id' => 'xxxxxxxxxxxxx', ]),
However, I get the following error:
`POST https://content.dropboxapi.com/2/files/upload` resulted in a `400 Bad Request` response: Error in call to API function "files/upload": This API function operates on a single Dropbox account, but the OAuth 2 ac (truncated...)
Why is this?
I would appreciate it if you could advise me.
Thank you.
- Greg-DB6 years ago
Dropbox Community Moderator
It looks like you or your HTTPS client truncated the error message. Please print out the full error message information, as it will contain more information about the specific error scenario.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 9 months ago
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 or Facebook.
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!