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 17 Next »

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:

  • Create: HTTP POST /<entity type name>
  • Read: HTTP GET /<entity type name>/<entity id>.<format
  • Update: HTTP PUT /<entity type name>/<entity id>.<format>
  • Delete: HTTP DELETE /<entity type name>/<entity id>

JSON and XML are fully supported "formats" for sending and receiving data.

Contents

Authentication

All web service requests require login, before accepting a query. A separate login call is not required for authentication. Login credentials are sent via HTTP Basic Authentication headers, in the requests. An example of the structure in PHP is shown below. Note, that all calls require this login to function properly.

HTTP Basic Authentication in PHP/Curl
<?php
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_admin:webservicepw"); // Your web service user credentials go here.

Warning!

A web service user account must meet proper naming convention to be valid for authentication. By default, the username must always start with "restws".


Querying EthosCE

Clients may use GET calls, to pull information from the system, including applying advanced filters and sorting.  Reference the Web Service Data Structures page for more information on each content type, their available fields, and accepted values. Most fields, including custom, are available to filter against. Multiple filters may be added to the query string via ampersands. The examples below detail common URL filter configurations.

Supported Operators

OperatorSyntaxExampleResult
>

[gt]=

user.json?uid[gt]='100'All users with uids greater than (but not equal to) 100
>=[ge]=node.json?created[ge]='1478044800'All nodes created before or equal to 11/02/2016 - 00:00 UTC
<[lt]=user.json?uid[lt]='500'All users with uids less than (but not equal to) 500
<=[le]=user.json?login[le]='1478278815'All users who have logged in before or equal to 11/04/2016 - 17:00 UTC
<>[ne]=credit_awarded.json?type[ne]='attendance'All awarded credit that is not Attendance
=

[eq]=
OR =

credit_awarded.json?type[eq]='ama'
credit_awarded.json?type='ama'
All awarded AMA credit
Contains[ct]=user.json?mail[ct]='ethosce.com'All users with an e-mail address which contains 'ethosce.com'
Starts with[sw]=user.json?name[sw]='jsmith'All users who have a username that starts with 'jsmith'


Examples

Return all credit awarded to user 2, sorted by awarded date
<?php
$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, "restws_admin:webservicepw"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// Your session token and content type
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
print curl_exec($curl);


Return all credit awarded after or on 08/20/2016 but before 08/21/2016
<?php
$curl = curl_init('http://your-domain/course_credit_awarded.xml?date[ge]=1471651200&date[le]=1471737600');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_admin:webservicepw"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// Your session token and content type
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
print curl_exec($curl);


Return all credit awarded that is not AMA
<?php
$curl = curl_init('http://your-domain/course_credit_awarded.xml?type[ne]=ama');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_admin:webservicepw"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// Your session token and content type
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
print curl_exec($curl);

Date Formatting

There are 2 date formats used when interacting with the web service, epoch and ISO 8601. The call being made informs which format to use. All GET calls, to pull information from EthosCE, require the URL friendly epoch time. A call for creation or update must use the database compatible ISO 8601 format (Y-m-d\TH:i:sZ). Additionally, both date formats must be converted to UTC before being sent, to ensure data integrity between systems.

Entered local time: December 31, 2014, 12:00PM EST
Converted to UTC/GMT: December 31, 2014, 5:00PM UTC
ISO 8601 format:  2014-12-31T17:00:00Z
Epoch format: 1420045200

Error Returns

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

  • 404: Not Found
    • The resource was not found
  • 403: Forbidden
    • The web service user does not have permission to use the resource. 
    • If this error is seen often, verify the session authentication step have been completed.
  • 406: Not Acceptable
    • The data sent to the web service is not in an acceptable format or is missing required fields. Check the documentation for the correct fields and format.
  • 200: OK
    • The web service call is successful. Data may or may not be returned depending on the operation.
  • 201: Created
    • The web service call created data

Example Scenarios

The following examples of standard calls to EthosCE are written in PHP, in JSON, using the Curl library.

  • No labels