Group Membership

Add (Remove) User to Group(s)

This API can be used to enroll a site user to one or more groups. The role of the member in the group can be specified while making this call. This API would also allow a group member to be removed from the group. A single API call can be used to subscribe one user to multiple groups. The group role can also be specified through this API.

 

API Details

Signature of API call

connection.invokeApi(String uri, String realUserName, Map<String, String> requestParameters);

See details about invoking API in general

 

Parameter 1 - URI

groupService.do

 

Parameter 2 - UserName

Username of any site administrator or group administrator

 

Parameter 3 - Request Parameters

Name Value Description
dispatch groupMembership API Method
userName Username of the user who needs to be enrolled or removed from group(s)  
groupId Comma separated valid groupids List of groups where the specified user would be enrolled or removed
join TRUE or FALSE True specifies that user need to be enrolled. False specifies user need to be removed from the group(s)
groupRole STUDENT or INSTRUCTOR or ADMIN Role of the user in the group

 

Response

1. Response on successful subscription

HTTP Response Code = HttpServletResponse.SC_OK

Response XML

<response code="0">
    <msgs>
         <msg>
             <code>0031</code>
             <value><![CDATA[New member(s) added to group]]></value>
         </msg>
    </msgs>
</response>

 

2. Response on successful withdrawl

HTTP Response Code = HttpServletResponse.SC_OK

Response XML

<response code="0">
    <msgs>
         <msg>
             <code>0032</code>
             <value><![CDATA[Member(s) removed from group]]></value>
         </msg>
    </msgs>
</response>

 

3. Response for unauthorized access

HTTP Response Code = HttpServletResponse.SC_UNAUTHORIZED

Response XML

<response code="-1">
    <msgs>
         <msg>
             <code>0005</code>
             <value><![CDATA[You are not allowed to perform this action.]]></value>
         </msg>
    </msgs>
</response>

 

Code Snippet

 

/*  Check API Call for detail generic code */
Map<String, String> parameters = Maps.newHashMap();
parameters.put(DISPATCH, "groupMembership");
parameters.put("userName", userName);
parameters.put("join", Boolean.TRUE.toString());
parameters.put("groupRole", "STUDENT");
           
// Add the user to multiple groups
parameters.put("groupId", "groupId1,groupId2");
String retStr = connection.invokeApi("groupService.do", adminUser, parameters);
System.out.println(retStr);          

// Withdraw the user from the groups
parameters.put("join", Boolean.FALSE.toString());
retStr = connection.invokeApi("groupService.do", adminUser, parameters);
System.out.println(retStr);

 

 


Rating: