Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: enrollment questions

...

Code Block
languagephp
linenumberstrue
<?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', // enrollmenttypeThis andis typeused shouldto beidentify updatedthe per client system. They aresource of the uniqueenrollment. identifiersOnly ofuse theletters, externalnumbers, system sending the calland underscores.
   'type' => 'webservicecourse_callenrollment', // FormattedThis is inthe lowerkey caseof alphanumericthe andenrollment underscorequestion charactersset. TheOnly twouse valuesletters, arenumbers, not required to be identicaland 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);
} 

...