Forum Discussion

lexomatic's avatar
lexomatic
New member | Level 2
3 years ago

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. 

2 Replies

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    3 years ago

    Hi lexomatic,

    The error message, you have posted, provides a good guidance how to solve your issue. Doesn't adding the header missing with your user id, as asked, solve it? 🤔

About Dropbox API Support & Feedback

Node avatar for 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!