Versions Compared

Key

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

...

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

    <format>

  • Update: HTTP PUT /<entity type name>/<entity id>

    .<format>

  • Delete: HTTP DELETE /<entity type name>/<entity id>

JSON and XML are

...

the supported "

...

formats" for sending and receiving data.

...

Examples

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

Contents

Table of Contents
minLevel3

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.

Creating a web service account

Follow the creating an account instructions and assign the “web service” role. Ensure the username begins with “restws.”

HTTP Basic Authentication in curl

...

Code Block
languagephp
titleRetrieving a user profile
<?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:

  • an additional token is required for security, and must be passed in a"X-CSRF-Token" HTTP header
  • you must specify the format being posted in an HTTP header, either "application/json" or "text/xml"
Code Block
languagephp
titleCreating 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 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"

Code Block
languagephp
titleUpdating a course's title
<?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.

Code Block
languagephp
titleListing awarded credit
<?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);
bash
 curl -X 'https://client.hosted.test.cloud.ethosce.com/user.json' --header 'Authorization: Basic cmVzdHdzX3JheTpXZWJzZXJ2aWNlMTIzIQ=='

Info

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

Operator

Syntax

Example

Result

>

[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 after 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'

Query Examples

Return all credit awarded to user 2, sorted by awarded date
Code Block
languagenone
https://client.hosted.test.cloud.ethosce.com/course_credit_awarded.xml?uid=2&sort=date&direction=DESC


Return all credit awarded after or on 08/20/2016 but before 08/21/2016

Code Block
languagenone
https://client.hosted.test.cloud.ethosce.com/course_credit_awarded.xml?date[ge]=1471651200&date[le]=1471737600


Return all credit awarded that is not AMA

Code Block
languagenone
https://client.hosted.test.cloud.ethosce.com/course_credit_awarded.xml?type[ne]=ama

Payload manipulation

The default for payload structure is to load the full field values for the first level of simple field types (text, select boxes, radio buttons, etc). More complex field types like the field collections (Profile Boards) or entity references (Course ACCME Data), will display a reference to that additional data type. Additionally, you can limit data returned to shrink returned payload size.

For more, please see Payload Manipulation.

Date Formatting

There are 2 date formats used when interacting with the web service, epoch and ISO 8601. The format used is dependent on what piece of data you wish to reference, usually either a property or a field. Additionally, both date formats must be converted to UTC before being sent, to ensure data integrity between systems.

Info

Entered local time: July 28 2018 08:00AM EDT
Converted to UTC/GMT: 28 Jul 2018 12:00:00 PM UTC
ISO 8601 format:  2018-07-28T12:00:00+00:00
Epoch format: 1532779200

Sending Date fields in queries

When using date fields as a parameter, the format must match the field you are referencing. As general guide, in courses, all added form fields, like custom fields, are formatted as ISO, and most date properties, like created and updated, are timestamps. Additionally, date fields with end dates require an added parameter to reference the correct date field.

Unix timestamp fields require an epoch timestamp format in the parameter, and are usually single date properties.

ISO date fields are more complex. They may have an End date, such as the expiration date in the Course Date field. These require an additional parameter to specify which of the two fields you would like to compare against, the start date (value) or the end date (value2).

Formatting an ISO date field with an end date i.e. Course Date (field_course_date), Event/Session date (field_course_event_date), or a custom form field
Course date Open: field_course_date[value][le]=2017-12-25
Course date Expiration: field_course_date[value2][le]=2017-12-25

Formatting an ISO date field without an end date i.e. Course Date (field_course_date), Event/Session date (field_course_event_date), or a custom form field
Custom: field_custom_date[value][le]=2017-12-25

Formatting a unix timestamp field for 2017-12-25 i.e. created and updated
created[ge]=1514160000

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.

Child pages (Children Display)
alltrue
pageWeb Service Examples
Child pages (Children Display)
pageWeb Services