REST protocol (with JSON/XML payload support)

Web service protocols ::: webservice_restjson
Maintained by Owen Barritt
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.
Latest release:
149 sites
10 downloads
10 fans
Current versions available: 1

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=...

Contributors

Owen Barritt (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments

Ukázat komentáře
  • manikandan Selvaraj
    středa, 22. března 2017, 18.45
    Hi Ownen,

    I tried this json structure too but no luck {"Courses":[{"fullname":"Bulk insert","shortname":"short bulk","categoryid":1}]}
  • Albert Leatherman
    úterý, 18. dubna 2017, 08.46
    Hi Owen, any chance of getting a quick example video for those of us aspiring to use server calls with Moodle but not yet quite up to speed on how they're done?
  • Mohammad Eftekhari
    pondělí, 17. července 2017, 16.37
    ( For those who don't know how to send the request via Command Line, like me some minutes ago. )

    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
  • Emil Wilmański
    pondělí, 23. října 2017, 07.57
    Hello Owen,
    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?
  • Chandni Pandya
    čtvrtek, 19. července 2018, 18.10
    This can be so helpful to web developer
  • Vivek Singh
    středa, 3. října 2018, 19.10
    Excellent plugin and very helpful for any magento developer.
  • Hodaya Ankri
    čtvrtek, 29. srpna 2019, 15.47
    Thanks for this useful plugin!!! It helps me a lot!!!
  • mango itsolutions
    středa, 18. března 2020, 15.40
    Hey Owen,
    I've used your plugin and found it is very well performing and any web developer can use it very easily
  • Marc Mathys
    neděle, 29. března 2020, 09.25
    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?
  • Navneet Kaur
    pátek, 8. října 2021, 21.09
    Best plugin
  • Noha James
    úterý, 17. prosince 2024, 14.41
    Thanks for sharing this post. It offers valuable information to the Web Developers
  • Daniel smith
    středa, 18. prosince 2024, 23.47
    Great plugin and very helpful for any Kentico developers
  • alouadifa ma
    neděle, 11. května 2025, 04.41
    This is a great enhancemen adding support for both JSON and XML with HTTP Accept headers brings much-needed flexibility to Moodle’s REST webservices! Whether you're integrating with legacy systems or modern APIs, this plugin bridges the gap beautifully. keeping it backward compatible is a smart move.
  • Shane Corn
    pondělí, 10. listopadu 2025, 18.27
    A video streaming app development company specializes in creating powerful, scalable, and high-performing streaming platforms for businesses across industries. These companies design customized video solutions that support live streaming, on-demand content, and real-time interactions. With expertise in advanced technologies like cloud computing, AI, and CDN integration, they ensure seamless streaming performance and top-notch security. Partnering with a professional video streaming app development company helps brands deliver engaging content, enhance user experience, and increase audience reach. Whether for entertainment, education, or fitness, video streaming solutions empower businesses to connect with users anytime, anywhere.
  • Vikas Sharma
    úterý, 11. listopadu 2025, 11.07
    DotStark provides Microsoft dynamics 365 consulting services. Hire Microsoft Dynamics 365 developers who have expertise in implementation, integration and customization.
1 2 3
Please login to post comments