Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 29 Current »

An external system may utilize the storage structure of the course record import feature to send course enrollments and course completions for any user in EthosCE, including those who have not yet created an account. The latter can be accomplished by sending an import record with the user's external identifier. This is especially useful if Creating a user via web service is not an option before enrolling a user via web service. Once the user is created, and logs in for the first time, they will be matched, via e-mail address or external identifier, and enrolled in the waiting courses.

If the enrollment triggers the awarding of credit from the course, rather than the credit being contained in the import, upon awarding the credit, all eligible credit reporters will fire. For example, PARS MOC board credit or a custom credit reporter.

Querying for an existing record

To prevent errors, and ensure data integrity, it is recommended to verify if a course import record already exists, before sending a creation request. The course import record is unique per user, per course. The query response will return either a list of users matching criteria or an empty array. If this list is empty, the import record does not exist in EthosCE and a creation request can be safely sent.

<?php
// #1 Verify if user record by sending a GET request to the system, searching by user id (uid) and course node id (nid)
$curl = curl_init("http://your-domain.com/transcript_import.json?uid=200&nid=50");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$json = curl_exec($curl);
$response = json_decode($json);

// A list of users matching criteria will be returned, or an empty array
$list = $response->list;

Creating a course import record via web service

Once verified it does not exist, a creation request can be sent. The request below will store an enrollment record for course node 200, for the user unregistered_user@you-domain.com.

nid: (Optional) The course node id.

external_nid: (Optional) The course's External course ID (found under Course settings). This may be used when the nid is unavailable or unknown.

external_mail: The e-mail address the user will have associated to their account at the time of login

imported: The import status of the record. When sending web requests, this is always 0. If set to 0, the record will be imported at next user login. If set to 1, the record has been imported previously. Upon login, the system will switch this flag to 1, preventing duplicate importing.

complete: The course completion status. If set to 0, the user will be enrolled in the course, only. If set to 1, the user will be enrolled, and also marked complete, triggering any eligible credits and course completion logic.


<?php
// Build a record to send, in JSON.
$import = array(
'external_mail' => 'unregistered_user@you-domain.com',
'nid' => 200,
'imported' => 0, // Must always be set to 0 to trigger import upon login
'complete' => 0,
);

// Send the record to the holding table
$curl = curl_init("http://your-domain.com/transcript_import.json");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);

$response = json_decode(curl_exec($curl));

// A list of users matching criteria will be returned.
$list = $response->list;

Successful Return

A successful return will provide an array in the list attribute, containing one item, with an array of user information.

  • No labels