...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php // Login to the site and request the access token $curl = curl_init('http://your-domain.com/restws/session/token'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); // Your web service user credentials goes here. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $token = curl_exec($curl); // The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%" // #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("X-CSRF-Token: $token", "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 transcript 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.
Info | |
---|---|
Request Attributes | nid: The course's Drupal 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. |
Code Block | ||||
---|---|---|---|---|
|
// Login to the site and request the access token
$curl = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); // Your web service user credentials goes here.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$token = curl_exec($curl);
// The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
// 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("X-CSRF-Token: $token", "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.
Return Attributes
.