Java API Call Examples

Java API Call Examples

Getting Groups in a Site:

API: public String getSiteGroupList(String groupNamePattern, PagedList pagination);

groupNamePattern : this parameter can be set to name of the group which you like to fetch. It can also contain % as the wild card character. Groups are searched in case insensitive manner.

Example:

PagedList pagination = new PagedList();
String response = connector.getSiteGroupList(null, pagination);
System.out.println(response);

Getting Users in a Site:

API: public String getUserList(String searchStr, String groupId, Boolean inactive, Boolean enrolled, PagedList pagination)

searchStr : this parameter can be set to first, last name/ username / email of the user which you like to fetch. By default search is made for all tokens separated by spaces. So if you search for John Doe, it would match all John and all Doe and you may get more results than what you expected. It can also contain % as the wild card character. Search is done in case insensitive manner.

groupId : group id (guid) of the group from which you want fetch the users list. By passing the group id, you are able to get group members.

inactive : Set it to null to get both active and inactive users. To get only active users, set it to false. To get only inactive users set it to true.

enrolled : Set it to true to fetch only users who currently

Example:

PagedList pagination = new PagedList();
pagination.setPageSize(10);
String response = connector.getUserList(null, null, false, null, pagination);
System.out.println(response);

Get User Details:

API: public String getUserDetails(String userName);

Example:

String response = connector.getUserDetails("jdoe");
System.out.println(response);

Update User Details:

API: public String updateUserDetails(String userName, String firstName, String lastName, String email);

Example:

String response = connector.updateUserDetails("jdoe", "John", "Doe", "jdoe1@acme.com");
System.out.println(response);

//Only first name, last name and email can be updated using this API

Deactivate a User:

API: public String deactivateUser(String userName);

Example:

String response = connector.deactivateUser("jdoe");
System.out.println(response);

Activate a User:

API: public String activateUser(String userName);

Example:

String response = connector.activateUser("ab11");
System.out.println(response);

Sync group-users:

API: public boolean addRemoveGroupAndMembers(Map<String, List<String>> groupUsersMap, RolesEnum role, String addMemberOperation);

groupUsersMap: The Map (first parameter) contains one entry for each group, so group name is the key in this map. The values are list of String which contains the user's information. At a minimum the string in the list must have usernames. But they can also contain Email and First-Last name separated by pipe character.

role: Should be set to STUDENT

addMemberOperation: Last parameter in the API can be either add or remove . If set to add, only the new groupMembers would be created. If set to remove, then any existing groupMembers which is not passed in the List corresponding to a group, would be removed from the group. If set to both, then new members not already present in the group would be added to group and any member which is not passed in the List would be removed.

Example 1: This example shows how to add 3 users in two Groups Grp1 and Grp2. The group with these names may or may not be pre-existing in the site. If the group doesn't exist, it would get created. You can pass any number of groups and list of usernames in the respective group in a single API call.

Map<String, List<String>> groupUsersMap = new HashMap<String, List<String>>();
        List<String> list = new ArrayList<String>();
        list.add("user1|user1@ee.com|Fname1 Lname1");
        list.add("user2|user2@ee.com|Fname2 Lname2");
        list.add("user3|user3@ee.com|Fname3 Lname3");
        
        groupUsersMap.put("Grp1", list);
        groupUsersMap.put("Grp2", list);
        boolean result = connector.addRemoveGroupAndMembers(groupUsersMap, RolesEnum.STUDENT, "add");
        System.out.println(result);

Example 2: This example shows how to remove all users from Grp1 except conf1 and  conf2 . You can use similar call to remove a specific user from the group by passing complete list of group members excluding the one you want to remove.

Map<String, List<String>> groupUsersMap = new HashMap<String, List<String>>();
        List<String> list = new ArrayList<String>();
        list.add("conf1");
        list.add("conf2");
        groupUsersMap.put("Grp1", list);
        boolean result = connector.addRemoveGroupAndMembers(groupUsersMap, RolesEnum.STUDENT, "remove");
        System.out.println(result);

 


Rating: