cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

V2 API MembersAddAsync

schek
Explorer | Level 3

I am adding a team member using .net Dropbox.Api class library. 

I could not figure a way to get IsSuccess or IsUserAlreadyOnTeam properties after MembersAddAsync is called. Since MembersAddAsync method returns the Task type, the only information I can got from the call is IsComplete.

How is it possible to determine if adding a member operation was succesful?

1 Accepted Solution

Accepted Solutions

Re: V2 API MembersAddAsync

Dropboxer
Dropboxer

You can do something like this:

var membersAddLaunch = await this.client.Team.MembersAddAsync(newMembers);
if (membersAddLaunch.IsComplete) {
    Console.WriteLine ("Adding members is complete.");
    foreach (var memberAdd in membersAddLaunch.AsComplete.Value) {
        if (memberAdd.IsSuccess) {
            Console.WriteLine ("Successfully added:");
            Console.WriteLine (memberAdd.AsSuccess.Value.Profile.Email);
        } else {
            Console.WriteLine (memberAdd);
        }
    }
} else if (membersAddLaunch.IsAsyncJobId) {
    Console.WriteLine ("Adding member via async job with job ID...");
    Console.WriteLine (membersAddLaunch.AsAsyncJobId.Value);
    // todo: poll MembersAddJobStatusGetAsync to get the result
}

View solution in original post

8 Replies 8

Re: V2 API MembersAddAsync

Dropboxer
Dropboxer

You should poll MembersAddJobStatusGetAsync after MembersAddAsync to get the result.

Re: V2 API MembersAddAsync

schek
Explorer | Level 3

Hi Greg, Thank you so much for your reply!

Do you have a sample code on how to get a pollArg parameter from this call? 

 

var Result = await client.Team.MembersAddAsync(iemember);

 

await client.Team.MembersAddJobStatusGetAsync(?);

Re: V2 API MembersAddAsync

Dropboxer
Dropboxer

I don't have a sample available, but you'll want to use MembersAddLaunch.IsAsyncJobId to check if the MembersAddLaunch you got from MembersAddAsync is an async job ID, and then use MembersAddLaunch.AsAsyncJobId to get the MembersAddLaunch.AsyncJobId, which you can pass to MembersAddJobStatusGetAsync.

Re: V2 API MembersAddAsync

schek
Explorer | Level 3

Greg,

 

Thank you for your help.

Unfortunately the Value of IsAsyncJobID is false and AsAsyncJobID is NULL, IsComplete is true after the call.

Not sure how could I get those values.

 

Re: V2 API MembersAddAsync

Dropboxer
Dropboxer
If IsComplete is true to begin with, you don't need to call MembersAddJobStatusGetAsync, since the operation already completed. Instead, you'd just use MembersAddLaunch.AsComplete to get the added member result.

So, to summarize, when you call MembersAddAsync, the operation will either complete immediately, or if not, it will give you a job ID that you can use with MembersAddJobStatusGetAsync to eventually get the result.

Re: V2 API MembersAddAsync

schek
Explorer | Level 3

It looks like the way to access IsSuccess property from AsComplete is:

new System.Collections.Generic.Mscorlib_CollectionDebugView<Dropbox.Api.Team.MemberAddResult>(Result.AsComplete.Value).Items[0].IsSuccess

But it gives me the error: 'Mscorlib_CollectionDebugView<T>' is inaccessible due to its protection level.
Is there something else I am missing?

 

Thank you again.

 

 

 

Re: V2 API MembersAddAsync

Dropboxer
Dropboxer

You can do something like this:

var membersAddLaunch = await this.client.Team.MembersAddAsync(newMembers);
if (membersAddLaunch.IsComplete) {
    Console.WriteLine ("Adding members is complete.");
    foreach (var memberAdd in membersAddLaunch.AsComplete.Value) {
        if (memberAdd.IsSuccess) {
            Console.WriteLine ("Successfully added:");
            Console.WriteLine (memberAdd.AsSuccess.Value.Profile.Email);
        } else {
            Console.WriteLine (memberAdd);
        }
    }
} else if (membersAddLaunch.IsAsyncJobId) {
    Console.WriteLine ("Adding member via async job with job ID...");
    Console.WriteLine (membersAddLaunch.AsAsyncJobId.Value);
    // todo: poll MembersAddJobStatusGetAsync to get the result
}

View solution in original post

Re: V2 API MembersAddAsync

schek
Explorer | Level 3

Perfet! This works. Thank you so much!

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?