Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
titleUpdating a course title
linenumberstrue
 <?php
$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 credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
// Token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"

// Only the fields being updated need to be sent
$course = array(
  'title' => 'My Title Update',
);

$curl = curl_init('http://your-domain.com/node/25'); // Note the 25, which is the nid of the course we are updating
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_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($course));
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$response = curl_exec($curl);
print 'Updating...';
$json = curl_exec($curl);
$cinfo = curl_getinfo($curl);
$response = json_decode($json);
if ($cinfo['http_code'] == 200 && empty($response)) {
  print 'The entity has been updated';
}

...

Code Block
languagephp
titleDeleting awarded credit
linenumberstrue
  $curl = curl_init("http://your-domain.com/course_credit_awarded/214"); // Note the 214, which is the entity id of the course_credit_awarded record associated to the user & course
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
  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);

  print 'Deleting...';
  $json = curl_exec($curl);
  $cinfo = curl_getinfo($curl);
  $response = json_decode($json);
  if($cinfo['http_code'] == 200 && empty($response)){
	print 'The entity has been deleted'.
  }

...