We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

tritnguyen's avatar
tritnguyen
Explorer | Level 3
3 years ago
Solved

How to get the admin memberID


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.

  • 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...

     

4 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    3 years ago

    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's avatar
    tritnguyen
    Explorer | Level 3
    3 years ago

    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's avatar
    tritnguyen
    Explorer | Level 3
    3 years ago

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

     

    Thank you.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    3 years ago

    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);
                }
            }
        }
    }

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,034 PostsLatest Activity: 31 minutes ago
409 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!