If Creating a user via web service is not an option before enrolling a user via web service, an An external system may utilize the storage structure of the course record import feature to send course enrollments and course completions of users for any user in EthosCE, including those who have not yet to create created an account. Once a 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.
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.
Code Block | ||
---|---|---|
| ||
<?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.
...
Code Block | ||
---|---|---|
| ||
<?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.