Moodle Plugins directory: REST protocol (with JSON/XML payload support) | Moodle.org
REST protocol (with JSON/XML payload support)
REST webservice protocol based on the standard core REST webservice, but with added support for JSON & XML payloads and supports using HTTP ACCEPTS headers for determining response format.
Installation
Simply place the plugin files in ./webservice/restjson
Setup
Should be enabled and setup in the standard way for webservices. See https://docs.moodle.org/29/en/Using_web_services for details.
Usage
The protocol can be called in the usual way for webservices with either JSON or XML data specified in content type (also backward compatible with current REST webservice so will also accept POST form data)
e.g. for a JSON payload
curl -H "Content-Type: application/json" -X POST -d '{"wsfunction":"...", "wstoken":"...",request object}' http://moodle.url/path/to/webservice/restjson/server.php
Parameters such as wsfunction and wstoken can also still be specified in the URL if required
curl -H "Content-Type: application/json" -X POST -d '{request object}' http://moodle.url/path/to/webservice/restjson/server.php?wsfunction=...&wstoken=...
Response format can also be set to XML or JSON by setting the accept HTTP header e.g. to send in JSON and receive in XML (by default same format is used to return as originally received) you could use:
curl -H "Content-Type: application/json" -H "Accept: application/xml"-X POST -d '{request object}' http://moodle.url/path/to/webservice/restjson/server.php?wsfunction=...&wstoken=...
How can i format the json object to post, because call core_course_create_courses method for create course, my json structure was [{"fullname":"Bulk insert","shortname":"short bulk","categoryid":1}]
But i got the error link {"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected"}
Could you please suggest what kind of structure i need to send course creation
I tried this json structure too but no luck {"Courses":[{"fullname":"Bulk insert","shortname":"short bulk","categoryid":1}]}
Because the request format is ambiguous. I couldn't understand how to send the "request Object". so I tried this and it worked :
curl -k -X POST -d "id=63&filename=windiff.zip" "https://localhost/moodle/webservice/rest/server.php?wsfunction=local_wstemplate_hello_world&wstoken=f5b0854a870e05f960cff39fc2a40665"
hope it helps
I try to use Moodle webservice within google apps, so json could be great to use, but I cant get that plugin to work.
Generally Moodle is not easy platform for anybody. So,
* my Moodle version is 3.1
* permission webservice/rest:use -> allow (standard REST works)
* token is valid (standard REST works)
* plugin webservice_restjson is enabled (0.4 for Moodle 2.9+ 2016021900)
* protocol REST protocol (with JSON/XML input support) -> enabled
request:
curl -H "Content-Type: application/json" -X GET http://elearning.casadelalengua.pl/webservice/restjson/server.php?wsfunction=core_course_get_courses&wstoken=33ff697d305xyz
I've got
{"exception":"webservice_access_exception","errorcode":"accessexception","message":"Wyj\u0105tek w kontroli dost\u0119pu"}
so I don't know what still I have wrong.
Can you help me with this problem?
I've used your plugin and found it is very well performing and any web developer can use it very easily