cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Discover new ways to use Dropbox or share your tips with other users like you. Get involved

.Net API SDK - Best way to connect to a Business Dropbox?

Explorer | Level 3

Hi,

We are in the process of adding Dropbox support to our application.  Basically this is so users have an option to store attachments in Dropbox (user creates a sales order in our app and wants to attach a Word doc to it for instance).  We are using the .Net Dropbox assemblies for this.  I have used the dropbox console to create a an app and created an access token for it.  I'm then using this code to try to connect -

DropboxClient dbx =
new DropboxClient("XXXXXX");

var result = await dbx.Users.GetCurrentAccountAsync();
var nameSpace = result.RootInfo.RootNamespaceId;
dbx = dbx.WithPathRoot(new PathRoot.Root(nameSpace));

But I get the following error when I the GetCurrentAccount call runs -
Error in call to API function "users/get_current_account":
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>.

I have not been able to find a C# sample that works yet for this.  Is there another way or what is the recommended way of doing this?  I would prefer to not have each user having to authenticate each time they want to access an attachment through our application.

I have cross-posted this in the API Support forum as well in case it gets more visibility there.

 

Thanks

5 Replies

Re: .Net API SDK - Best way to connect to a Business Dropbox?

Dropboxer

This error message indicates that the access token you're using is for a "Dropbox Business API" app, which connects to entire Dropbox Business teams, but the method you're trying to use is for specific Dropbox accounts. 

If you want any kind of Dropbox account (Business or not) to be able to connect to your app, you should instead register a "Dropbox API" app. That kind of app needs to be authorized by each end-user, at which point the app receives an access token for that user's account and can call methods like GetCurrentAccountAsync without additional configuration.

Alternatively, if you only want to connect Business accounts, you can use your "Dropbox Business API" app registration. That kind of app only need to be authorized by a team admin, at which point the app receives an access token for that entire team. Your app would then need to additionally specify which team member to operate on when making an account-specific call such as GetCurrentAccountAsync. You can do so by first making a DropboxTeamClient object and calling DropboxTeamClient.AsMember with the relevant team member ID to get a DropboxClient for that team member.

Reply
Loading...

Re: .Net API SDK - Best way to connect to a Business Dropbox?

Explorer | Level 3

I have been trying to use the AsMember method and it seems to always throw this error when I use it - "Invalid select user id format"

DropboxTeamClient teamClient = new DropboxTeamClient(OAUTHTOKEN);

var results = await teamClient.Team.MembersListAsync();

string memberID = string.Empty;
foreach (var member in results.Members)
{
    if (member.Profile.Email.Equals("tcash@mac.com", StringComparison.OrdinalIgnoreCase))
    {
        memberID = member.Profile.AccountId;
        if (memberID.StartsWith("dbid:", StringComparison.OrdinalIgnoreCase))
        {
            memberID = memberID.Substring(5);
        }
        break;
    }
}

var dbx = teamClient.AsMember($"dbmid:{memberID}");

The member ID I get from the member profile is in the format of "dbidface without mouthXXXXX", while the code I have found in the forms seems to want to set it as "dbmidface without mouthXXXXX".  I've tried both styles and neither worked.

Reply
Loading...

Re: .Net API SDK - Best way to connect to a Business Dropbox?

Dropboxer

The AsMember method expects the "team member ID", which is the ID that starts with "dbmid:". Dropbox supplies these values directly, and you should not attempt to modify them.

The team member ID is available as MemberProfile.TeamMemberId (not MemberProfile.AccountId).

Reply
Loading...

Re: .Net API SDK - Best way to connect to a Business Dropbox?

Explorer | Level 3

Ok, so I did try using that value and it gave me the same error.

Reply
Loading...

Re: .Net API SDK - Best way to connect to a Business Dropbox?

Dropboxer

Can your share your current code for that? I just modified your earlier code and it worked fine for me:

DropboxTeamClient teamClient = new DropboxTeamClient(ACCESS_TOKEN);

var results = await teamClient.Team.MembersListAsync();

string memberID = string.Empty;
foreach (var member in results.Members)
{
    if (member.Profile.Email.Equals(EMAIL_ADDRESS, StringComparison.OrdinalIgnoreCase))
    {
        memberID = member.Profile.TeamMemberId;
        break;
    }
}
//or use MembersGetInfoAsync to look up a specific member directly

var dbx = teamClient.AsMember(memberID);
var result = await dbx.Users.GetCurrentAccountAsync();
Reply
Loading...
Developer & API Discussions

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about Developer & API Discussions.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post