Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The web service feature has the ability to update enrollment group courses with a simple call to update the associated field.


NOTE: When creating or updating an entity

The update to the field is a complete overwrite of the values.

Creating a course

The PHP/Curl script below will update the the enrollment  group

Updating a course's title
<?php
$domain = '76.localhost';
$userpass = 'restws_webservice:restws_webservice';
// Login to the site and request the access token

$curl = curl_init('http://' . $domain . '/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); // Your web service user credentials goes here.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
// The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
print_r($token);
// Build a course to send, in JSON. The fields and allowed values are available on the full documentation site.
$course_list = array(
  "field_enrollment_group_courses" => array(
    array('id' => 15),
    array('id' => 16),
    array('id' => 17),
  ),
);
$enrollment_group_nid = 3112;
$json = json_encode($course_list);
$curl = curl_init('http://' . $domain . '/node/' . $enrollment_group_nid);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$http_return = curl_exec($curl);
$response = json_decode($http_return);
print_r($response);

  • No labels