Module name and id

Module name and id

by Marco J -
Number of replies: 1

Hi everyone, sorry in advance, I'm new to Moodle smile

I'd like to test my angular front performing a web service call with the standard web service function core_course_get_course_module_by_instance which has 2 parameters "module" (string - of component type) and "instance" (integer) but how do I find the module name and instance id of a given module?

My course "GDP" has a quiz activity module "test: 1" how can I find out the module name and instance ID?

In the below REST call I have tried the component name "mod_quiz" and the instance id "1":

www.mymoodle.com/webservice/rest/server.php?&token=....&wsfunction=core_course_get_course_module_by_instance&module=&instance=1

My error is "Invalid external api parameter: the value is "TEST%1instance=1", the server was expecting "component" type"

But if I try the frankenstyle name "mod_TEST: 1" or variants without punctuation "mod_test_1" don't work either.


The code given in the https://docs.moodle.org/dev/Course_module looks good, but it assumes I already know the

global $DB;

$course = $DB->get_record('course', array('id' => $courseid));

$info = get_fast_modinfo($course); print_object($info);

is the 'course' in this case 'gdp' and then what is the get course id function?

Average of ratings: -
In reply to Marco J

Re: Module name and id

by Marco J -

UPDATE: I changed the webservice to be core_course_get_contents instead because that only uses the course ID which is visible in the URL of the course after you click on it: https://your.moodle.com/course/view.php?id=3

not only that but this function is much more useful (for my learning purposes) because it actually lays out everything in the course in XML format (or you can use moodlewsrestformat=json)

<SINGLE>
<KEY name="id">
<VALUE>22</VALUE>
</KEY>
<KEY name="name">
<VALUE>MODULE 6</VALUE>
</KEY>
<KEY name="visible">
<VALUE>1</VALUE>
</KEY>
<KEY name="summary">
<VALUE/>
</KEY>
<KEY name="summaryformat">
<VALUE>1</VALUE>
</KEY>
<KEY name="section">
<VALUE>6</VALUE>
</KEY>
<KEY name="hiddenbynumsections">
<VALUE>0</VALUE>
</KEY>
<KEY name="uservisible">
<VALUE>1</VALUE>
</KEY>
<KEY name="availabilityinfo">
<VALUE null="null"/>
</KEY>
<KEY name="modules">
<MULTIPLE> </MULTIPLE>
</KEY>
</SINGLE>