One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
lexomatic
3 years agoNew member | Level 2
Targeting a folder at the root of a business account.
I am trying to upload files into a folder at the root of a DropBox Business account.
I can list all the folders including the target folder by using the following.
$cheaders = array('Authorization: Bearer '.DROPBOX_APP_TOKEN,
'Content-Type: application/json');
$ch = curl_init('https://api.dropboxapi.com/2/team/namespaces/list');
$payload = json_encode( array( "limit"=> 100 ) );
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec($ch);
$folders = json_decode($response);
foreach($folders as $namespaces){
var_dump($namespaces);
}
That works and returns a listing of the namespace ID's and the human readable folder names including the one I would like to upload to at the Root level (outside of the members folders)
object(stdClass)#8 (3) {
["name"]=>
string(10) "RootTest"
["namespace_id"]=>
string(11) "123456789"
["namespace_type"]=>
object(stdClass)#9 (1) {
[".tag"]=>
string(13) "shared_folder"
}
}
However, when I try to target this folder [123456789] using the Dropbox-API-Path-Root to upload files I get the following error.
"Error in call to API function "files/upload": This API function operates on a single Dropbox account, but the OAuth 2 access token you provided is for an entire Dropbox Business team. Since your API app key has team member file access permissions, you can operate on a team member's Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user" URL parameter to specify the exact user <https://www.dropbox.com/developers/documentation/http/teams>"
$path = 'test.txt';
$fp = fopen($path, 'rb');
$size = filesize($path);
$cheaders = array('Authorization: Bearer '.DROPBOX_APP_TOKEN,
'Content-Type: application/octet-stream',
'Dropbox-API-Path-Root: {".tag": "namespace_id", "namespace_id":"123456789"}',
'Dropbox-API-Arg: {"path":"/test.txt","mode":{".tag":"add"}}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
fclose($fp);
How do you target a folder at the Root of the dropbox account which has the namespace id of 123456789 in this example.
Any help is greatly appreciated.
- Greg-DB
Dropbox Staff
That's correct, since your access token is connected to the team itself, you'll need to specify a particular member to use a user API endpoint like /2/files/upload. You can find more information on that in the documentation under the "Member file access" section.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 2 hours ago
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!