How to Create and Edit a Module through a Webservice

How to Create and Edit a Module through a Webservice

by Martin Breuss -
Number of replies: 3

There have been similar questions asked earlier, but I haven't come to a proper understanding of the situation yet.

Is there a possibility to create or edit a course module (e.g. Page or Quiz) through a webservice function?

I have looked through this list and multiple discussion threads, and it doesn't seem to be implemented.

This feature seems like a much needed update to me, since creating content directly in Moodle is error-prone, tedious, hard to version-control, and difficult to keep up-to-date.

With the possibility to create and update course module resources through a webservice, this opens up the possibility to allow content creators to:

  • Create Productively: create and edit resources in their favorite text editor, even offline
  • Version-Control: keep their content under version-control
  • Integrate: integrate with other webservices, and e.g. allow making post-commit hooks that update the course when the content got updated on a GitHub repository
  • Uploadcreate a whole course offline, then upload it to Moodle

Does such a webservice exist that exposes this capabilities through a function? If not, why not? And is anyone working on it?

I'd be thankful to learn more and for any tips and pointers. Thanks!

Average of ratings: Useful (1)
In reply to Martin Breuss

Re: How to Create and Edit a Module through a Webservice

by Pierre Cartier -
I'm actualy looking for it too ! Specially to edit date restriction acces using timestamp. This is visible in core_course_get_contents or core_course_get_course_module, but no create option. I'm looking in the moodle code to search all actions allowed by core_course_edit_module because the documentation isn't really explicit about that.
Average of ratings: Useful (1)
In reply to Martin Breuss

Re: How to Create and Edit a Module through a Webservice

by Anastasia Leyva -
Hi Martin,

Did you find the solution to this?

Thank you,
Anastasia
In reply to Anastasia Leyva

Re: How to Create and Edit a Module through a Webservice

by Martin Breuss -

Sorry, I didn't manage to find anything useful. There are two alternatives, both not great IMO:

  1. Understand the Database structure and directly insert your content into the SQL database
  2. Understand how Moodle's `.mbz` (= ZIP) exports are structured, recreate such a structure from your content locally, compress it, and upload it to Moodle

I haven't done either because:

  1. seems pretty insecure and I don't want to mess with the database directly, plus the table relations for some of the resources are pretty confusing for me... 
  2. the file structure and partial files look quite messy, they're all in XML, and it just sounds like a huge workload to build something custom that recreates that

Maybe someone smarter than me who has experience with PHP could fetch the code from Moodle's codebase that does the compression (when creating a course export) and could repurpose it as a stand-alone script that takes a folder with Markdown files as input. That'd be great smile But sorry, I don't have anything useful myself.