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.