API Client Code - cURL Example

The following example shows authentication using curl commands. Anybody who needs to make API calls to fetch and update data into their microsite through HTTP calls can refer these.

  1. Setup initial call to get SESSION_ID . This curl request will store response cookies in cookies.txt

  curl  --cookie-jar cookies.txt https://<microsite-url>/oltpublish/site/connect.do

       2. Authenticate with  api_username and password. Pass in the SESSION_ID cookie returned in #1. In below 

curl -b cookies.txt --cookie-jar authenticated.txt  --data "username=<api_username>&password=<password>" https://<microsite-url>/oltpublish/site/index.do

       3. Sample API call to return user lists. This is authenticated API to get the list of users.  Similarly, other authenticated API calls can be made.

header REAL_UNAME with format  uname+"|"+(email != null?email:"")+"|"+(flname!=null?flname:"")

Example value for REAL_UNAME: "jdoe|jdoe@edubrite.com|John Doe"

If you don't want to pass email and fullname, you can simply use user name

REAL_UNAME: jdoe

curl -b authenticated.txt  --header "REAL_UNAME:jdoe"  https://<microsite-url>/oltpublish/site/userService.do?dispatch=list

Creating user session in browser

To create user session using API, and bypassing the signin page of lms you can use the createSessionAPI. E.g.

curl -b authenticated.txt  --header "REAL_UNAME:jdoe"  https://<microsite-url>/oltpublish/site/signinService.do?dispatch=createSessionApi

Sample response you will get upon successful call

<response code="0">
    <msgs>
        <msg>
            <code>0</code>
            <value>
            <![CDATA[Success]]>
            </value>
        </msg>
    </msgs>
    <data>
        <session>
            <sessionId><![CDATA[0Gxxkt0dw_utQpcg6Ca2kt9iMuoQs7u70RJjRHmt5osmgnTZcqVo2PJX8JeMDeKEM8O5RE*]]></sessionId>
            <sessionInfo><![CDATA[0Gxxkt0dw_uOSLTPtQpcgyrfJ6eFZnIpRKe-uzilq4kjDfv8OG9BNRaPvoe_5rkSZuRNHC-S7IPlVibmzDnEe4LcGOaD4CJbv9nnzEw*]]></sessionInfo>
        </session>
    </data>
</response>   

Once you have the SessionId and SessionInfo, you can open the browser with below url and lms will recognize you as a valid signed in user jdoe.

 

https://<microsite-url>/oltpublish/site/index.do?sessionId=<replace session-id>&sInfo=<replace session-info>

 


Rating: