API - Create User (With Custom Properties)

User Creation (With Custom Properties)

This API can be used to create one or more users 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 create
userName jdoe
firstName John
lastName Doe
email jdoe@edubrite.org
password userpassword (password is optional, if you plan to utilize SSO with any system, don't pass this parameter to create a user without any password in LMS. Such users can only login using SSO)
openId Optional - openId can be used to uniquely identify the user (this field can be used as a custom unique key)

Custom Properties are passed in following manner

customUpdPropMap['property name'] = value

customUpdPropMap['address'] 4128 Business Center Drive
customUpdPropMap['department'] sales

 

Response

1. Response on successfully creating user

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 also contains information of newly created user -->

<data>
<user id="4687042a-2155-11e6-b63c-6ce229284b01"
    siteRole="STUDENT" status="ACTIVE">
    <userName><![CDATA[jdoe]]></userName>
    <firstName><![CDATA[John]]></firstName>
    <lastName><![CDATA[Doe]]></lastName>
    <email><![CDATA[jdoe@edubrite.com]]></email>
        <customProperties>
                <prop>
                    <name><![CDATA[address]]></name>
                    <value><![CDATA[4128 Business Center Drive]]></value>
                    <displayValue><![CDATA[4128 Business Center Drive]]></displayValue>
                </prop>
                <prop>
                    <name><![CDATA[dept]]></name>
                    <value><![CDATA[sales]]></value>
                    <displayValue><![CDATA[Ssales]]></displayValue>
                </prop>
        </customProperties>
        <groupMembers>
                    <groupMember groupId="3fa10542-60ef-11e5-9f32-02e883d7aedf"
                        role="STUDENT">
                        <groupName><![CDATA[Training]]></groupName>
                    </groupMember>                    
        </groupMembers>
</user>
</data>
</response>

 

2. Response on user creation error

HTTP Response Code = HttpServletResponse.SC_NOT_FOUND

Response XML

<response code="-1">
    <msgs>
         <msg>
             <code>0026</code>
             <value><![CDATA[ serviceuser_0 serviceuser_1 already present. Please rename them]]></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>();
    populateMapForUserCreation(parameters);
    parameters.put("dispatch", "create");
   
    String retStr = connection.invokeApi("userService.do", "chenry", parameters);
    System.out.println(retStr);

    private void populateMapForUserCreation(Map<String, String> parameters) {
           parameters.put("userName", "jdoe");
            parameters.put("firstName", "John");
            parameters.put("lastName", "Doe");
            parameters.put("password", "welcome");
            parameters.put("email", "jdoe@edubrite.com");
            parameters.put("customUpdPropMap['address']", "4128 Business Center Drive");
            parameters.put("customUpdPropMap['dept']", "sales");
}

 

 


Rating: