How to create category from api

How to create category from api

by rajeeva d -
Number of replies: 2

I am trying to create a category from api.But i am unable to do it.


I have tried adding category from code level and added to "course_categories" table.Record is inserted but the category is not showing up in the website.


Can anyone suggest

Average of ratings: -
In reply to rajeeva d

Re: How to create category from api

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I think you mean course categories,

in this case there are number of functions in the class coursecat, you would need create() function: https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/lib/coursecatlib.php#L344

Course categories is not an API, so there is no dev docs page about it. From time to time we discuss the phpdocs generation from moodle core but because of very different code style in different parts of moodle the generated phpdocs are almost impossible to navigate through. 


P.S. you can see the examples of calling coursecat::create() in the unittest: https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/lib/tests/coursecatlib_test.php

Just don't create courses in the real system using data generator please! I actually would not recommend creating courses from the code, better use the tool upload courses.