All course fields, including custom, can be sent via web service, during creation and update calls. The following structure applies to any course type in the system, including sessions, with updates to the appropriate fields. The course type may be updated by changing the type value, seen on line 13.
Internal Value | |
---|---|
Course | course |
Session | group_event_series_event |
NOTE: When creating or updating an entity
An additional token is required for security, and must be passed in an X-CSRF-Token HTTP header. In the example below, the system is queried for this token on lines 2-7, and it is applied to the call on line 28.
For any call, you must specify the Content-Type format being posted in an HTTP header, either "application/json" or "text/xml".
Most content types in Ethos use the body field for the main content, except Courses, which use the field_course_summary field.
Creating a course
<?php $curl = curl_init('http://your-domain.com/restws/session/token'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); // 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%" // Build a course to send, in JSON. The fields and allowed values are available on the full documentation site. $course = array( 'title' => 'my new course', 'type' => 'course', 'field_course_summary' => array( 'value' => 'this is the summary<b>This is bold</b>', 'format' => 'full_html' ), 'author' => 1, 'status' => 1, ); $json = json_encode($course); $curl = curl_init('http://your-domain.com/node.json'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); $response = json_decode(curl_exec($curl)); // The response looks like (JSON decoded) /* stdClass Object ( [uri] => http://your-domain.com/node/33 [id] => 33 [resource] => node [uuid] => 5121134e-dbfa-4011-939e-180290a02618 ) */
Updating a course's title.
When updating any content, the payload sent is trimmed down to only the fields being updated. To update the course created in the previous section, we use the URI sent, http://your-domain.com/node/33.
<?php $curl = curl_init('http://your-domain.com/restws/session/token'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); $token = curl_exec($curl); print "Received token: " . $token . "\n"; // Token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%" // Build a course // The fields and allowed values are available on the full documentation site. $course = array( 'title' => 'my updated course', ); $json = json_encode($course); $curl = curl_init('http://your-domain.com/node/33'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //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")); $response = curl_exec($curl); print $response;