Versions Compared

Key

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

The response from a web service request will change depending on the type of request sent. Some responses contain an array of information, others only HTTP Status codes. The example return arrays shown have been decoded from JSON for readability.

Table of Contents
maxLevel4
minLevel2

Read (GET)

Read, or GET, requests, return an array of information, including any records found to match the given criteria. The response array is structured to handle paginated requests, and includes a 'list' of the records on the current page.

title
Info

Return Attributes

self: The current page being viewed

first: The first page in the data set

last: The last page in the data set. If this matches the value in first, the data set has been returned in full in the list option.

next: The next page in the data set, following the current page, self

prev: The previous page in the data set, preceding the current page, self

list: The data range of the current self request page

...

A request to verify enrollment of user 200 in course 300, where the user is enrolled in the course. The call http://your-domain.com/course_enrollment.json?uid=200&nid=300 will return the following:

Response with values
Code Block
languagephp
titleResponse with values
linenumberstrue
stdClass Object
(
    [self] => http://your-domain.com/course_enrollment?uid=200&nid=300 // The current page the list value displaying information
    [first] => http://your-domain.com/course_enrollment?uid=200&nid=300&page=0
    [last] => http://your-domain.com/course_enrollment?uid=200&nid=300&page=0
    [list] => Array
        (
            [0] => stdClass Object
                (
                    [eid] => 185
                    [nid] => stdClass Object
                        (
                            [uri] => http://your-domain.com/node/310
                            [id] => 310
                            [resource] => node
                            [uuid] => 9aabcf09-58c3-4679-85b3-c5f7ddc93ac6
                        )

                    [uid] => stdClass Object
                        (
                            [uri] => http://your-domain.com/user/200
                            [id] => 200
                            [resource] => user
                            [uuid] => ba5bc8af-25d7-48de-bb54-87ae70ac33b5
                        )

                    [enrollmenttype] => 
                    [status] => 1
                    [created] => 1459800985
                    [timestamp] => 1459800985
                    [enroll_end] => 0
                    [code] => 
                    [user_type] => 
                    [data] => 
                    [feed_nid] => 
                )
        )
)


A request to verify enrollment of user 200 in course 400, where the user is not enrolled in the course. The call http://your-domain.com/course_enrollment.json?uid=200&nid=400 will return the following:

...

Response without values
true
linenumbers
Code Block
stdClass Object
(
    [self] => http://your-domain.com/course_enrollment?uid=200&nid=400 // The current page the list value displaying information
    [first] => http://your-domain.com/course_enrollment?uid=200&nid=400&page=0
    [last] => http://your-domain.com/course_enrollment?uid=200&nid=400&page=0
    [list] => [] 
)


A request for all enrollments in the system, http://your-domain.com/course_enrollment.json will return the following:

...

...

Initial response with multple pages
Code Block
linenumberslanguagetruephp
stdClass Object
(
    [self] => http://your-domain.com/course_enrollment
    [first] => http://your-domain.com/course_enrollment?page=0
    [last] => http://your-domain.com/course_enrollment?page=3
    [next] => http://your-domain.com/course_enrollment?page=1
    [list] => Array
        (
            [0] => stdClass Object{ ... }
            [1] => stdClass Object{ ... }
            [2] => stdClass Object{ ... }
			...
        )
)


A request to review the second page of results from all enrollments in the system, http://your-domain.com/course_enrollment.json?page=1 will return the following:

...

...

View page response
linenumbers
Code Block
true
languagecollapsephptrue
stdClass Object
(
    [self] => http://your-domain.com/course_enrollment?page=1
    [first] => http://your-domain.com/course_enrollment?page=0
    [last] => http://your-domain.com/course_enrollment?page=3
    [prev] => http://your-domain.com/course_enrollment?page=0
    [next] => http://your-domain.com/course_enrollment?page=2
    [list] => Array
        (
            [0] => stdClass Object{ ... }
            [1] => stdClass Object{ ... }
            [2] => stdClass Object{ ... }
			...
        )
)

Create (POST)

Creation, or POST, requests, return an array of basic information about the new created entity. The HTTP status code returned will be 201 CREATED for successful requests.

Info
title

Return Attributes

uri: The web URI

id: The entity id

resource: The entity type

uuid: The unique universal id

Example Response

A user creation call.

View creation response
Code Block
linenumbers
languagephp
titleView creation response
true
stdClass Object
(
    [uri] => http://your-domain.com/user/200
    [id] => 200
    [resource] => user
    [uuid] => 2fd044c5-ff4a-4bfe-8472-9b9b56eb0fc6
)


false
Info
icon

See

the

a full creation request at Creating a user via web service

Update (PUT)

Update, or PUT,  requests, do not return any data, other than the a data array. HTTP headers are returned, which can be used to verify success. A status code of 200 OK, indicates a successful call.

title
Info

Return Attributes

None

Example Request

Updating a course title
Code Block
languagephp
titleUpdating a course title
linenumberstrue
 <?php
$curl = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
// Token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"

 <?php
// Only the fields being updated need to be sent
$course = array(
  'title' => 'My Title Update',
);

$curl = curl_init('http://your-domain.com/node/25'); // Note the 25, which is the nid of the course we are updating
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($course));
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$response = curl_exec($curl);
print 'Updating...';
$json = curl_exec($curl);
$cinfo = curl_getinfo($curl);
$response = json_decode($json);
if ($cinfo['http_code'] == 200 && empty($response)) {
  print 'The entity has been updated';
} been updated';
}


Info

See an update request as part of  Manipulation of course objects via web services

Delete (DELETE)

Similar to UpdatesUpdate, Delete requests do not return any data, other than the a data array. HTTP headers are returned, which can be used to verify success. A status code of 200 OK, indicates a successful deletion call.

title
Info

Return Attributes

None

Example Request

Deleting awarded credit
Code Block
languagephp
titleDeleting awarded credit
linenumberstrue
  $curl = curl_init("http://your-domain.com/course_credit_awarded/214"); // Note the 214, which is the entity id of the course_credit_awarded record associated to the user & course
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
  curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

  print 'Deleting...';
  $json = curl_exec($curl);
  $cinfo = curl_getinfo($curl);
  $response = json_decode($json);
  if($cinfo['http_code'] == 200 && empty($response)){
	print 'The entity has been deleted'.
  }

...