There are multiple ways of sending enrollments via web service. The basic call is the most common, however, enrollment questions are also supported.
Table of Contents |
---|
Creating an enrollment via web service
...
In this example, the course node id (nid) we want to enroll the user in is 300 and the Drupal user ID (uid) is 200.
Code Block | ||||
---|---|---|---|---|
| ||||
<?php // Verify if the user is enrolled in the course $curl = curl_init("http://your-domain.com/course_enrollment.json?uid=200&nid=300"); 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 go here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $json = curl_exec($curl); $response = json_decode($json); $list = $response->list; // See note below if(empty($list)){ $data = array( 'nid' => 300, 'uid' => 200, 'enrollmenttype' => 'webservice_call', // This is used to identify the source of the enrollment. Only use letters, numbers, and underscores. 'type' => 'course_enrollment', // This is the key of the enrollment question set. Only use letters, numbers, and underscores. 'status' => 1, ); // Send the enrollment creation request $curl = curl_init("http://your-domain.com/course_enrollment"); 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 go here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($curl); } |
...
Code Block | ||
---|---|---|
| ||
{"uri":"http://your-domain.com/course_enrollment/458","id":"458","resource":"course_enrollment"} |
Info |
---|
For an explanation of the information returned from the verification request, see Web Service Responses. |
Creating/Updating an enrollment containing questions
Enrollment questions can be updated during an enrollment web service call. However, only questions which are set to Show this field on enrollment, are supported via the web service.
...