cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Problem sharing folders and adding team members

Problem sharing folders and adding team members

AS131
Explorer | Level 4

I am exploring Dropbox Business API. I am trying to create a shared folder programmatically from a web application and then share it with bonafide team members.

My First Business Trial App is created with access type : "Team member file access".

FolderMetadata foldermetadata = client.files().createFolderV2(strFolderName).getMetadata();

I get error in the above line of code, though the client used here has TEAM_ADMIN role :
if(com.dropbox.core.v2.team.AdminTier.TEAM_ADMIN == member.getRole()) {
client = teamClient.asMember(profile.getTeamMemberId());
}//end if

 

12:05:32,385 ERROR [stderr] (default task-42) com.dropbox.core.BadRequestException: Error in call to API function "files/create_folder:2": Unexpected select user header. Your app does not have permission to use this feature
12:05:32,386 ERROR [stderr] (default task-42) at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:317)
12:05:32,387 ERROR [stderr] (default task-42) at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:129)
12:05:32,387 ERROR [stderr] (default task-42) at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:300)
12:05:32,387 ERROR [stderr] (default task-42) at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:116)
12:05:32,387 ERROR [stderr] (default task-42) at com.dropbox.core.v2.files.DbxUserFilesRequests.createFolderV2(DbxUserFilesRequests.java:580)
12:05:32,387 ERROR [stderr] (default task-42) at com.dropbox.core.v2.files.DbxUserFilesRequests.createFolderV2(DbxUserFilesRequests.java:607)

I created anothe App with access type : "Team member management".

Now the error is :

(default task-46) com.dropbox.core.v2.sharing.AddFolderMemberErrorException: Exception in 2/sharing/add_folder_member: "no_permission" (user message: You don’t have permission to perform this action.)
12:14:36,337 ERROR [stderr] (default task-46) at com.dropbox.core.v2.sharing.DbxUserSharingRequests.addFolderMember(DbxUserSharingRequests.java:130)
12:14:36,339 ERROR [stderr] (default task-46) at com.dropbox.core.v2.sharing.DbxUserSharingRequests.addFolderMember(DbxUserSharingRequests.java:155)

How do I manage both the actions - to create a Shared Folder and to share it selectively with Team Member(s) ?

 

3 Replies 3

Greg-DB
Dropbox Staff

Using a Dropbox Business API app with the "team member file access" permission is the right way to do this. That enables the app to use the "member file acces" feature, which includes the ability to create folders, share folders, and add members to shared folders.

Can you share the full code to reproduce the 'no_permission' error so we can take a look? Thanks in advance! 

AS131
Explorer | Level 4

Hello Greg,

Thanks for your reply, I am unable to attach the full code (getting "An Unexpected Error has occurred" message). So here it is :

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;

import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.DbxTeamClientV2;
import com.dropbox.core.v2.files.FolderMetadata;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.ListFolderResult;
import com.dropbox.core.v2.files.Metadata;
import com.dropbox.core.v2.sharing.MemberSelector;
import com.dropbox.core.v2.users.FullAccount;
import com.dropbox.core.v2.users.FullTeam;
import com.dropbox.core.v2.sharing.ShareFolderLaunch;
import com.dropbox.core.v2.sharing.SharedFolderMetadata;
import com.dropbox.core.v2.sharing.AddMember;
import com.dropbox.core.v2.team.TeamMemberInfo;
import com.dropbox.core.v2.team.TeamMemberProfile;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

public class DbxBMain {
private static final String ACCESS_TOKEN = "****************************************************************"; //Access Token

public static void main(String args[]) throws DbxException, IOException {
try {
// Create Dropbox client
DbxRequestConfig config = new DbxRequestConfig("Dropbox R & D");

DbxTeamClientV2 teamClient = new DbxTeamClientV2(config, ACCESS_TOKEN);

DbxClientV2 client = null;

/********************************************************************************************/
// Get current account info
System.out.println("Dropbox Account - Complete Info. : " + teamClient.team().getInfo().toStringMultiline());

/********************************************************************************************/
// Get current team info - List of team members.

List<TeamMemberInfo> team = teamClient.team().membersList().getMembers();
if(team != null) {
Iterator iter = team.iterator();
while (iter.hasNext()) {
TeamMemberInfo member = (TeamMemberInfo) iter.next();
TeamMemberProfile profile = member.getProfile();

System.out.println("\n/--------------------------------------------------------------------------------------------/");
System.out.println("Team Member - Role : " + member.getRole().toString());
System.out.println("Team Member Info - Complete Info. : " + member.toStringMultiline());
System.out.println("/--------------------------------------------------------------------------------------------/\n");

if(com.dropbox.core.v2.team.AdminTier.TEAM_ADMIN == member.getRole()) {
client = teamClient.asMember(profile.getTeamMemberId());
}//end if
}//end while
}//end if

/********************************************************************************************/
// Create Folder and add File
try {

String[] strMails = {"xxxx@xxxxxxxxxx.xxx", "xxxx@xxxxxxxxxx.xxx"};//Random E-Mail IDs - not in any Team / Group

for (int i = 0; i < strMails.length; i++) {

MemberSelector member = MemberSelector.email(strMails[i]);
System.out.println("\n/--------------------------------------------------------------------------------------------/");
System.out.println("Email Value : " + member.getEmailValue());
System.out.println("/--------------------------------------------------------------------------------------------/\n");

String strMemberName = member.getEmailValue().substring(0, (member.getEmailValue().indexOf("@", 1)));
System.out.println("\n/--------------------------------------------------------------------------------------------/");
System.out.println("Member Name : " + strMemberName);
System.out.println("/--------------------------------------------------------------------------------------------/\n");

AddMember am = new AddMember(member);
List<AddMember> members = new ArrayList<AddMember>();
members.add(am);

String strFolderName = "/DBX_Test_Folder_" + strMemberName + "_" + Integer.toString(new Random().nextInt(100));
FolderMetadata foldermetadata = client.files().createFolder(strFolderName);
System.out.println("\n/--------------------------------------------------------------------------------------------/");

System.out.println("Sharing Folder : " + foldermetadata.getPathDisplay());
System.out.println("/--------------------------------------------------------------------------------------------/\n");

ShareFolderLaunch sfl = client.sharing().shareFolder(foldermetadata.getPathDisplay());

// Folder sharing
System.out.println("Shared Folder ID : " + sfl.getCompleteValue().getSharedFolderId());
client.sharing().addFolderMember(sfl.getCompleteValue().getSharedFolderId(), members);
} //for

} catch (DbxException ex) {
System.err.println("Error making API call : " + ex.getMessage());
System.exit(1);
return;
}
/********************************************************************************************/

System.out.println("\n/--------------------------------------------------------------------------------------------/");
ListFolderResult result = client.files().listFolderBuilder("").withRecursive(true).start();
while(true) {
List<Metadata> entries = result.getEntries();
for (Metadata metadata : entries) {
//if (metadata instanceof FileMetadata) {
//FileMetadata fileMetadata = (FileMetadata) metadata;
//if (metadata.getPathLower().endsWith(".csv")) {
System.out.println("Name : " + metadata.getPathLower());
System.out.println("\n/--------------------------------------------------------------------------------------------/");
System.out.println("Metadata - Complete Info. : " + metadata.toStringMultiline());
System.out.println("/--------------------------------------------------------------------------------------------/\n");
//}//end if
//}//end if
}//end for

if(result.getHasMore()) {
result = client.files().listFolderContinue(result.getCursor());
} else {
break; //no more entries to process
}//end if-else
}//end while

System.out.println("/--------------------------------------------------------------------------------------------/\n");

/********************************************************************************************/
} catch(Exception e) {
e.printStackTrace();
}//end try-catch
}//end main
}//end DbxTest


I had set the following permissions before I got "No Permission" error :

Sharing files and folders externally - Off
Editing external folders - Off
Sharing links externally - Off
Default shared link privacy - Anyone


After making the following changes, the code worked and folders were getting created.

Sharing files and folders externally - On
Editing external folders - On
Sharing links externally - On
Default shared link privacy - Team Only



Greg-DB
Dropbox Staff

Thanks for following up. I'm glad to hear you were able to get this working. Yes, that previous access control setting would have prevented you from adding those other accounts, so it looks like this is working as expected.

Need more support?