API - Add user to group(s)

Add User to Group(s)

This API can be used to add user to one or more groups in the microsite. The API is a restrictive one and can be called by an admin of the site only. Any other user trying to invoke this API would result in an error being returned by the 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

userService.do

 

Parameter 2 - UserName

Username of any site administrator

 

Parameter 3 - Request Parameters

Name Value
dispatch addToGroups
Either userName or id is required
userName jdoe
id a570e68e-2134-11e6-b63c-6ce229284b01
groupId

81154232-7e81-11e4-b5ad-fb29daca67a3, xxx-xxx-xxx-xxx-xxx

comma separated group ids, to get group ids, use the group list call first

groupRole

Optional. If not provided, default role is  STUDENT role

Values STUDENT / ADMIN / INSTRUCTOR

 

Response

1. Response on successfully adding user to group

HTTP Response Code = HttpServletResponse.SC_OK

Response XML

<response code="0">
    <msgs>
         <msg>
             <code>0018</code>
             <value><![CDATA[User(s) added successfully]]></value>
         </msg>
    </msgs>

</response>

 

2. Response on invalid user id / name

HTTP Response Code = HttpServletResponse.SC_NOT_FOUND

Response XML

<response code="-1">
    <msgs>
         <msg>
             <code>0004</code>
             <value><![CDATA[Unable to find User with matching id]]></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 = new HashMap<String, String>();
    parameters.put("userName", "jdoe");

    parameters.put("groupId", "81154232-7e81-11e4-b5ad-fb29daca67a3");
    parameters.put("dispatch", "addToGroups");
   
    String retStr = connection.invokeApi("userService.do", "chenry", parameters);
    System.out.println(retStr);
   


Rating: