EthosCE has a powerful RESTful webservice that can be used to send or retrieve information from an EthosCE website through HTTP requests.

The web service extension supports full CRUD (Create, Read, Update, Delete) for resources:

Examples

Any language that can make HTTP requests can be used. Here are some examples in PHP/CURL:

<?php
// Retrieve a profile in XML:
$curl = curl_init('http://your-domain.com/profile2.xml?user=2');
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);
$response = curl_exec($curl);
print $response;

NOTE: When creating or updating an entity:

<?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 goes 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 = json_decode(curl_exec($curl));
// The response looks like (JSON decoded)
/*
stdClass Object
(
    [uri] => http://743.localhost/node/33
    [id] => 33
    [resource] => node
    [uuid] => 5121134e-dbfa-4011-939e-180290a02618
)
*/

Updating a course's title. Note the usage of "PUT" instead of "POST"

<?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 goes 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/30');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials goes 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;


You can also list entities using the webservice, and apply sorts and filters.

<?php

// Show recent credit awarded
$curl = curl_init('http://your-domain/course_credit_awarded.xml?uid=2&sort=date&direction=DESC');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
print curl_exec($curl);

Errors

Errors are reported from the RESTful web service with HTTP codes:

Additional Links