Making an API call
While making any API call first ensure that the client has the Connection object with the required set of cookie information in it (SessionId and SessionInfo). Check the API Authentication document to learn about how to obtain the Connection object. The two values are sent as cookies in the HTTP API call. The username corresponding to the real user who is supposedly making the API call is sent in the HTTP request header. All other required parameters are sent as regular request parameters. The return string is an XML with a predefined standard structure. Each call would have its own defined structure which would be enclosed inside a standard wrapper XML. Also every service returns a HTTP status code through the HTTPServletResponse object. HTTPServletResponse.SC_OK is set for all successfully completed service call, otherwise appropriate codes are returned. Client code can check the returned value to take appropriate action.
Code Snippet
API Call
The invokeApi() method in the Connection object makes the actual API call. The invokeApi() method sends the two cookies along with username (second parameter) in the header and the other required parameters (third parameter) as request parameters. The return is a standard XML wrapper containing the actual XML data. The HTTP response code would also be available in the Connection object after every API call.
/*
* Populate the request parameters needed for the specific API call
*/
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(DISPATCH, "subscribeByAuthCode");
parameters.put("eventId", EVENT_ID);
parameters.put("code", AUTHCODE);
/*
* Makes the actual API call.
* Param1 : Service URI
* Param2 : Site user (username) who is making the API call
* Param3 : Request parameter map
*/
connection.invokeApi("eventService.do", "username", parameters);
/*
* Returned XML data
*/
String responseXml = connection.getLastResponseXml();
/*
* Returned HTTP status code
*/
int httpCode = connection.getLastHTTPCode();
Response
Response of all API calls is the HTTP response code and a standard XML structure, which is shown below
HTTP Response Code = HttpServletResponse.SC_OK (Or some other code)
Response XML
<!--
Response is enclosed in a response wrapper which would have two separate parts, Message and Data. Response code indicates the overall success/failure of the API call.
0 indicates success and any negative value indicates failure.
Message can have a list of messages with each having a code and a text value.
Actual data is enclosed inside <data> </data> construct. The structure inside data node varies from one API call to another.
-->
<response code="0">
<msgs>
<msg>
<code>0</code>
<value><![CDATA[Success]]></value>
</msg>
</msgs>
<data>
<events numItems="1" currPage="0" pageSize="10">
<event id="3df4617a-5b72-11e1-8a65-0030489d05ee" type="CBT" status="IN_PROGRESS">
<name><![CDATA[American History Exam 1]]></name>
<startDate>1329706769000</startDate>
<endDate>1330140589000</endDate>
<resultDate>1330139989000</resultDate>
<subscribed>false</subscribed>
<partiallySubscribed>false</partiallySubscribed>
<canSubscribe>false</canSubscribe>
<eventItems>
</eventItems>
</event>
</events>
</data>
</response>
Related Pages
Group Management
Javascript
- Customization On Payment Page
- Validate IP Address while accessing the course
- UI Customization JavaScript Functions
- Verify Custom properties during Test Taking
- Verifying User Properties During Test
- JS Example
- example_custom_scripts
- Test Taking - Customization using callback mechanism
- Cms Calendar Example
Reports
Enrollment Management
- API - Update Event Subscription
- API - Create ExamTestInstance
- Update Program Member - via Program Session Id
- Update Program Member
- API - Self Enroll in Course Session
- Update Course Session Member
- API - Self Enroll in Program Session
- API - Self Enroll in Event
- API - Enroll Users in Course Session
- API - Enroll Users in Program Session
- API - Enroll Users in Event
- API - Enroll Users in Program
Other
Introduction
Report
- Get Sites Metadata
- Get Open Learning Items List
- API - Program Enrollment Summary
- API - Course Enrollment Summary
- Get Catalog Items List
- API - Course Session Members list
- API - Program Members List
- Event participants list
- Api - Test Attempts (Test Instances) List
- Test instance details list
- Api - Non Subscribed Event List
- Api - Subscribed Event List
- API - List All Report Schedules
- API - Get Latest Report Content For A Given Schedule ID
- API - Get Report Content For A Given Report ID
- API - List Reports For A Given Schedule
User Management
- API - User list
- API - Get user details
- Api - User Creation
- API - Create User (With Custom Properties)
- API - Update User
- API - Rename User
- API - Add user to group(s)
- API - Remove user from group(s)
- Merge User Accounts
- API - Activate User
- API - Deactivate User
- API - Change User's Origin Site
- Api - User Login (Creating User Session)
eCommerce
API Documentation
Examples
- User Creation
- User Update
- User List
- Get User Details
- Add User to Group(s)
- Remove User from Group(s)
- User Activate
- User Deactivate
- User Login
- Group List
- Group Membership
- Course Subscription(Coupon Code)
- Subscribed Events List
- Non Subscribed Events List
- Test Instances in Microsite
- Forum APIs
- Javascript Example
Client Example
Quick Links
- Home
- Getting Started
- Knowledgebase
- Video Tutorials
- Google Apps Integration
- Gilly (Plugin for Atlassian Confluence)
Group Management
Javascript
- Customization On Payment Page
- Validate IP Address while accessing the course
- UI Customization JavaScript Functions
- Verify Custom properties during Test Taking
- Verifying User Properties During Test
- JS Example
- example_custom_scripts
- Test Taking - Customization using callback mechanism
- Cms Calendar Example
Reports
Enrollment Management
- API - Update Event Subscription
- API - Create ExamTestInstance
- Update Program Member - via Program Session Id
- Update Program Member
- API - Self Enroll in Course Session
- Update Course Session Member
- API - Self Enroll in Program Session
- API - Self Enroll in Event
- API - Enroll Users in Course Session
- API - Enroll Users in Program Session
- API - Enroll Users in Event
- API - Enroll Users in Program
Other
Introduction
Report
- Get Sites Metadata
- Get Open Learning Items List
- API - Program Enrollment Summary
- API - Course Enrollment Summary
- Get Catalog Items List
- API - Course Session Members list
- API - Program Members List
- Event participants list
- Api - Test Attempts (Test Instances) List
- Test instance details list
- Api - Non Subscribed Event List
- Api - Subscribed Event List
- API - List All Report Schedules
- API - Get Latest Report Content For A Given Schedule ID
- API - Get Report Content For A Given Report ID
- API - List Reports For A Given Schedule
User Management
- API - User list
- API - Get user details
- Api - User Creation
- API - Create User (With Custom Properties)
- API - Update User
- API - Rename User
- API - Add user to group(s)
- API - Remove user from group(s)
- Merge User Accounts
- API - Activate User
- API - Deactivate User
- API - Change User's Origin Site
- Api - User Login (Creating User Session)
eCommerce
API Documentation
Examples
- User Creation
- User Update
- User List
- Get User Details
- Add User to Group(s)
- Remove User from Group(s)
- User Activate
- User Deactivate
- User Login
- Group List
- Group Membership
- Course Subscription(Coupon Code)
- Subscribed Events List
- Non Subscribed Events List
- Test Instances in Microsite
- Forum APIs
- Javascript Example
Client Example
Quick Links
- Home
- Getting Started
- Knowledgebase
- Video Tutorials
- Google Apps Integration
- Gilly (Plugin for Atlassian Confluence)
Comment