General developer forum

Creating a Course and Content via API's

 
Picture of John Bartlett
Creating a Course and Content via API's
 

Hi All,

Apologies in advance if this question has been asked and answered before, I had a hunt of the forums and couldn't find anything that really answered what I was looking for.

I have a requirement to be able to create a course plus all of it's relevant material (e.g. modules, quizzes etc.) using an API (preferably REST), the reason for this is I am holding the content I want turned into a course in a separate system which I want to automatically convert (and update) as it gets added to or changed.

From reviewing the API documentation I can see an API for creating a course but unless I am missing something I cannot see anyway of creating the course content itself or configuring the course options?

Any help or pointers in the right direction would be greatly appreciated.

Thanks,

John

 
Average of ratings: -
Picture of Gavin Henrick
Re: Creating a Course and Content via API's
Group Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Be sure to check the API documentation in your own Moodle site for the full list of API available.

It is found under 

So for example when creating the course you can set all the course options as below.

General structure
//courses to create
list of (
object {
fullname string //full name
shortname string //course short name
categoryid int //category id
idnumber string Optional //id number
summary string Optional //summary
summaryformat int Default to "1" //summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN)
format string Default to "topics" //course format: weeks, topics, social, site,..
showgrades int Default to "1" //1 if grades are shown, otherwise 0
newsitems int Default to "5" //number of recent items appearing on the course page
startdate int Optional //timestamp when the course start
enddate int Optional //timestamp when the course end
numsections int Optional //(deprecated, use courseformatoptions) number of weeks/topics
maxbytes int Default to "0" //largest size of file that can be uploaded into the course
showreports int Default to "0" //are activity report shown (yes = 1, no =0)
visible int Optional //1: available to student, 0:not available
hiddensections int Optional //(deprecated, use courseformatoptions) How the hidden sections in the course are displayed to students
groupmode int Default to "0" //no group, separate, visible
groupmodeforce int Default to "0" //1: yes, 0: no
defaultgroupingid int Default to "0" //default grouping id
enablecompletion int Optional //Enabled, control via completion and activity settings. Disabled, not shown in activity settings.
completionnotify int Optional //1: yes 0: no
lang string Optional //forced course language
forcetheme string Optional //name of the force theme
courseformatoptions Optional //additional options for particular course format
list of (
object {
name string //course format option name
value string //course format option value
}
)}
)

However the is not a add_module that I can see, at least.

 
Average of ratings: -
Picture of John Bartlett
Re: Creating a Course and Content via API's
 

Hi Gavin,

Thank you for your response.

Yes I spotted that API and from my understanding that is used to create the top level course definition which is a great start however what I require is also the ability to define the underlying content that goes into the course programmatically.

As there doesn't appear to be any API's around content creation (as you have pointed out above) I assume I would have top potentially provide this in some way, I wonder whether the best approach would be to write a plugin that exposes a set of my own API's that allows content to be built directly against the Database?

Thanks,

John

 
Average of ratings: -
Picture of Gavin Henrick
Re: Creating a Course and Content via API's
Group Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

If you have the development skills, you could look to create webservices that expose the apis for the activities and resources themselves,

and share them back with as tracker submissions to enhance the core set of APIs.

Maybe Juan could advise on this?

G

 
Average of ratings: -