Moodle API - Create Assignments

Moodle API - Create Assignments

by Shah Haque -
Number of replies: 3

Hi,

I want to create assignments inside a course via the core API but when I look at the available functions inside the API there is no such function. Can anyone advise?

Average of ratings: -
In reply to Shah Haque

Re: Moodle API - Create Assignments

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I've not double-checked the available API functions (but I'd quite believe there isn't a specific function to do what you want). However, it is fairly straightforward to create a plugin (probably a "local" plugin) and define your own API functions, so that is a route you could go down (as you're posting in the developer forum, I'm assuming that would be a possibility for you - if not, there are various Moodle Partners who can offer development services to help with that).

In reply to Davo Smith

Re: Moodle API - Create Assignments

by Shah Haque -
Hi there,

Sorry for the late reply, I was looking via plugins that creates sections inside an course. but in that section I would like to use a function that creates an activity/resource.

I have found an plugin that creates sections which is called: Webservice manage sections

here is the link: https://moodle.org/plugins/local_wsmanagesections

thing is I am using Moodle 4.4 and this plugin has support up to Moodle 4.2.

but as for creating assignments, I guess I will need to create a section first then create an activity/resource?
In reply to Shah Haque

Re: Moodle API - Create Assignments

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

As it stands, you're going to have to create your own API. It would be good if each activity had an add_instance api, but sadly they don't, yet. Adding in assignments is a little complicated because there are submission and feedback sub-plugins which you may need to consider when adding a new instance.

For my org we have assignments created automatically via our student records system, for which we have a web service. You won't be able to use it out of the box, because it was designed for our own needs, but you're welcome to browse the code for inspiration.

Because we're creating assignments from some outside event that triggers their creation, we actually store the data in a separate table, so we can recreate it if necessary from within Moodle without needing to go back to our SRS (a task actually creates the assignment). We also have some predefined defaults, such as the section we put the assignment in, so checkout the settings.

Here's the link: https://github.com/ltu-solent/moodle-local_solsits