RESTful protocol

Premium Certified Partner
Maintained by Catalyst IT
A REStful webservice plugin for Moodle LMS This plugin allows Moodle's webservice interface to operate in a more RESTFul way. Instead of each webservice call having a URL query parameter define what webservice function to use, webservice functions are made available by discrete URLs.
Price option: Free

Supports Moodle 3.1-4.5 See all versions
Latest release: 1 year ago
Installations: 1239
Downloads (last 90 days): 187

Frankenstyle name: webservice_restful
Web service protocols

Comments

Comments are no longer open for new posts. Existing comments remain available to read.

Where can I find documentation for the restful webservices, I can only find the ones for rest.
Hi,
When using nginx as a reverse proxy in front of Moodle, we noticed that header names are automatically normalized to lowercase.
For example, a client request like:
-H "Content-Type: application/json"
-H "Accept: application/json"
-H "Authorization: xxx"
will arrive at the backend as:
-H "content-type: application/json"
-H "accept: application/json"
-H "authorization: xxx"
Therefore, in the webservice_restful plugin, it is important to ensure that header processing logic treats header names case-insensitively, according to the HTTP/1.1 specification (RFC 7230), which defines header field names as case-insensitive.
I suggest updating the code to normalize header keys to lowercase before checking or comparing them, or at least allow case-insensitive matching.
Thanks for considering this!

I am happy to announce that the plugin received the "Moodle Workplace ready" award after being tested and found useful by the Worplace team (MDLSITE-6684). Congratulations!

Hi, do you have postman collection for all of the endpoints?
Does this work with Moodle 3.10?
Does anyone have any idea why this plugin should not work together with the following plugin?
https://moodle.org/plugins/local_wsgetroles
Using the ootb invocation, I get back a list of roles:
============================================================
curl --globoff ^
-d "wstoken=YmZjNDA5ZDQ4NGM5OWE1OWYxYTlmODg5" ^
-d "wsfunction=local_wsgetroles_get_roles" ^
-d "moodlewsrestformat=json" ^
"http://10.0.0.121/webservice/rest/server.php"
============================================================
But using the following returns nothing:
============================================================
curl --globoff ^
-H "Content-Type: application/json" ^
-H "Accept: application/json" ^
-H "Authorization: YmZjNDA5ZDQ4NGM5OWE1OWYxYTlmODg5" ^
"http://10.0.0.121/webservice/restful/server.php/local_wsgetroles_get_roles"
============================================================
Hi. I have created the webservice by following the documentation, I'm getting the token for the service i created but when i try to access this url 'https: //localhost/webservice/restful/server.php/core_course_get_courses' using the generated token im getting 404 Object Not found error.
Hi. Can this be used by a device to send/receive JSON data (files) and store it in moodle for later access by the device or user?
I got it working by using this code:
import requests
headers = {
'Accept': 'application/json',
'Authorization': '555',
'Content-Type': 'application/json'
}
body = '{"options": {"ids":[6]}}'
url = 'https: //server/webservice/restful/server.php/core_course_get_courses'
resp = requests.get(url, headers=headers, data=body)
print(resp)
data = resp.json()
print(data)
The issue was the capitalization of the headers in Accept Authorization and Content-Type. If someone else sees this and copies it pay attention to the space in the url so that I wouldn't get denied by the spam server on these comments and change the authorization number and of course not store it in the scripts.
I have this working from the notes above:
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H 'Authorization: 555' \
-d'{"options": {"ids":[6]}}' \
"https: //server/webservice/restful/server.php/core_course_get_courses"
But I'm trying to convert that into a python request and keep getting back a 401 response:
headers = {
'content-type': 'application/json',
'accept': 'application/json',
'authorization': '5555'
}
body = {"options": {"ids":[6]}}
url = 'https: //server/webservice/restful/server.php/core_course_get_courses'
resp = requests.post(url, headers=headers, json=body)
data = resp.json
print(data)
Does anybody see what I'm doing wrong here?
Would anyone know if this plugin is more powerful/stable/easier to user, etc... than the .NET API Wrapper?
http://coderespect.blogspot.com/2017/06/moodle-api-net-wrapper.html
https://github.com/syedrizwanm/Moodle.API.Wrapper
Is there a SWAGGER like page anywhere to enumerate and test all the RESTFUL commands/methods?
Hello all,
This plugin could be a life saver!!! I plan to use Office 365 Flow to interact with Moodle and having a RESTFUL API is key! Does anyone know if it works with Moodle 3.7?
The authorization header was stripped by my version of Apache 2, resulting in a noauthheader error. It worked when added this directive:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
I also encountered a contenttype header error, which I solved by adding this code to webservice/restful/locallib.php, line 164 (get_requestformat function):
if (isset($_SERVER['CONTENT_TYPE'])) {
$requestformat = ltrim($_SERVER['CONTENT_TYPE'], 'application/');
} else {
// Raise an error if content header not supplied.
$ex = new \moodle_exception('notypeheader', 'webservice_restful', '');
$this->send_error($ex, 400);
}
- This function originally expected a HTTP_CONTENT_TYPE header, but it was CONTENT_TYPE in my case (using the sample curl from this page).
Hi Matt.. i have done what you said and I have been able to remove the braces {} a stated in the auth token . thanks as this was not posted by the http://www.epoxyflooringlasvegas.com/epoxy-floor-las-vegas/