cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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: 

How to get the admin memberID

How to get the admin memberID

tritnguyen
Explorer | Level 3
Go to solution


Hi All,

I want to keep track of the admin team member ID of the person who invite or remove the new user for the team. If I got the event and I can print it as:

 

{
"timestamp" : "2022-11-03T17:17:51Z",
"event_category" : "members",
"event_type" : {
".tag" : "member_change_status",
"description" : "Changed member status (invited, joined, suspended, etc.)"
},
"details" : {
".tag" : "member_change_status_details",
"new_value" : "invited",
"previous_value" : "not_joined"
},
"actor" : {
".tag" : "admin",
"admin" : {
".tag" : "team_member",
"account_id" : "admin_account_idxxxxxxxxxxxxxxxxx",
"display_name" : "TestAdmin",
"email" : "testAdmin@test.com",
"team_member_id" : "admin_team_member_idxxxxxxxxxxxxx"
}
},
"origin" : {
"access_method" : {
".tag" : "end_user",
"end_user" : {
".tag" : "web",
"session_id" : "session_idxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"geo_location" : {
"ip_address" : "0.0.0.",
"city" : "",
"region" : "",
"country" : ""
}
},
"involve_non_team_member" : false,
"context" : {
".tag" : "team_member",
".tag" : "team_member",
"account_id" : "team_member_account_idxxxxxxxxxxxxxxxxxxx",
"display_name" : "",
"email" : "testTeamMember@test.com",
"team_member_id" : "team_team_member_idxxxxxxxxxxxxxxxxxxxxxxx"
},
"participants" : [ ],
"assets" : [ ]
}


I want to get the team_member_id of the admin which is the value: "admin_team_member_idxxxxxxxxxxxxx". However when I tried to get to the Actor object using the function call:

 

 

TeamEvent event = events.get(i);
String adminTeamMemberId = event.getActor().getAdminValue().....

 

 

I got the error:

Exception in thread "main" java.lang.IllegalStateException: Invalid tag: required Tag.ADMIN, but was Tag.APP
at com.dropbox.core.v2.teamlog.ActorLogInfo.getAdminValue(ActorLogInfo.java:241)

In addition, the object that is returned from the event.getActor().getAdminValue() does not have the get method to the the team_member_id value. I would like to get that value. What should I do?

Thank you.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

The actor won't necessarily be an admin. For example, if the operation was performed via the API, it will be an app instead. If you attempt to get the actor information as an admin when it wasn't an admin, you'll get that error. You should check the actor type before accessing it as that type to avoid that.

 

Also, you would need to cast the UserLogInfo for the admin actor as TeamMemberLogInfo to get the team member ID.

 

Here's a small sample that shows how to do both of these:

if (event.getActor().isAdmin()) {
    String adminAccountId = event.getActor().getAdminValue().getAccountId();
    System.out.println(adminAccountId);
    String adminTeamMemberId = ((TeamMemberLogInfo)event.getActor().getAdminValue()).getTeamMemberId();
    System.out.println(adminTeamMemberId);
} else if (event.getActor().isApp()) {
    String appId = event.getActor().getAppValue().getAppId();
    System.out.println(appId);
} // and so on; check and handle other types...

 

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

The actor won't necessarily be an admin. For example, if the operation was performed via the API, it will be an app instead. If you attempt to get the actor information as an admin when it wasn't an admin, you'll get that error. You should check the actor type before accessing it as that type to avoid that.

 

Also, you would need to cast the UserLogInfo for the admin actor as TeamMemberLogInfo to get the team member ID.

 

Here's a small sample that shows how to do both of these:

if (event.getActor().isAdmin()) {
    String adminAccountId = event.getActor().getAdminValue().getAccountId();
    System.out.println(adminAccountId);
    String adminTeamMemberId = ((TeamMemberLogInfo)event.getActor().getAdminValue()).getTeamMemberId();
    System.out.println(adminTeamMemberId);
} else if (event.getActor().isApp()) {
    String appId = event.getActor().getAppValue().getAppId();
    System.out.println(appId);
} // and so on; check and handle other types...

 

tritnguyen
Explorer | Level 3
Go to solution

I had the sample code in my test as:

 

List<TeamEvent> events = eventRes.getEvents();
for(int i = 0; i < events.size(); i++)
{
TeamEvent event = events.get(i);
if(event.getEventCategory() == MEMBERS &&
event.getEventType().tag() == MEMBER_CHANGE_STATUS){
if(event.getDetails().getMemberChangeStatusDetailsValue().getNewValue() == INVITED)
{
if (event.getActor().isAdmin()) {
String adminAccountId = event.getActor().getAdminValue().getAccountId();
System.out.println(adminAccountId);
String adminTeamMemberId = ((TeamMemberLogInfo)event.getActor().getAdminValue()).getTeamMemberId();
System.out.println("admin teamMemberId: " + adminTeamMemberId);
}
}
}
else if(event.getDetails().getMemberChangeStatusDetailsValue().getNewValue() == REMOVED)
{
if (event.getActor().isAdmin()) {
String adminAccountId = event.getActor().getAdminValue().getAccountId();
System.out.println(adminAccountId);
String adminTeamMemberId = ((TeamMemberLogInfo)event.getActor().getAdminValue()).getTeamMemberId();
System.out.println("admin teamMemberId: " + adminTeamMemberId);
}
}
}

However, when I tried the code above I got the error:

Exception in thread "main" java.lang.IllegalStateException: Invalid tag: required Tag.MEMBER_CHANGE_STATUS_DETAILS, but was Tag.MEMBER_CHANGE_ADMIN_ROLE_DETAILS
at com.dropbox.core.v2.teamlog.EventDetails.getMemberChangeStatusDetailsValue(EventDetails.java:15913)

It seems that the check for Admin Role using the function call event.getActor().isAdmin() does not work.

tritnguyen
Explorer | Level 3
Go to solution

I am sorry that I made a mistake when I did a copy and paste. It works OK now.  

 

Thank you.

Greg-DB
Dropbox Staff
Go to solution

You seem to have your "else if" attached to the wrong "if" above it, so it's not properly guarded by the ".isMemberChangeStatus" check.

 

Also, you don't need to check the tag yourself like that. You should use the supplied the methods instead.

 

Here's a corrected version that runs successfully for me:

List<TeamEvent> events = eventRes.getEvents();
for (int i = 0; i < events.size(); i++) {
    TeamEvent event = events.get(i);
    if (event.getEventCategory() == EventCategory.MEMBERS &&
            event.getEventType().isMemberChangeStatus()) {
        if (event.getDetails().getMemberChangeStatusDetailsValue().getNewValue() == MemberStatus.INVITED) {
            if (event.getActor().isAdmin()) {
                String adminAccountId = event.getActor().getAdminValue().getAccountId();
                System.out.println(adminAccountId);
                String adminTeamMemberId = ((TeamMemberLogInfo) event.getActor().getAdminValue()).getTeamMemberId();
                System.out.println("admin teamMemberId: " + adminTeamMemberId);
            }
        } else if (event.getDetails().getMemberChangeStatusDetailsValue().getNewValue() == MemberStatus.REMOVED) {
            if (event.getActor().isAdmin()) {
                String adminAccountId = event.getActor().getAdminValue().getAccountId();
                System.out.println(adminAccountId);
                String adminTeamMemberId = ((TeamMemberLogInfo) event.getActor().getAdminValue()).getTeamMemberId();
                System.out.println("admin teamMemberId: " + adminTeamMemberId);
            }
        }
    }
}
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    tritnguyen Explorer | Level 3
What do Dropbox user levels mean?