I have Moodle 4.4.3 installed. Multiple courses are added to the system. I have access to the Moodle API. I am using the API call core_course_get_contents
to the content of one of my courses. Here is the response:
[
{
"id": 38,
"name": "Section Title",
"visible": 1,
"summary": "",
"summaryformat": 1,
"section": 1,
"hiddenbynumsections": 0,
"uservisible": true,
"modules": [
{
"id": 21,
"url": "https://example.com/mod/wiki/view.php?id=21",
"name": "Reading materials",
"instance": 5,
"contextid": 44,
"visible": 1,
"uservisible": true,
"visibleoncoursepage": 1,
"modicon": "https://example.com/theme/image.php/boost/wiki/1727859606/monologo?filtericon=1",
"modname": "wiki",
"purpose": "collaboration",
"branded": false,
"modplural": "Wikis",
"availability": null,
"indent": 0,
"onclick": "",
"afterlink": null,
"customdata": "\"\"",
"noviewlink": false,
"completion": 0,
"downloadcontent": 1,
"dates": [],
"groupmode": 0
}
]
}
]
The course page contains 1 entry with a Wiki activity added. I understand that ID=38 is the entry "Section Title" on the course page, while ID=21 is the Wiki ID. Then I use Moodle API call mod_wiki_get_page_contents
with pageid=21
to try to obtain the contents of the Wiki activity. However the response is not showing the content of the Wikipedia, but the contents from other pages:
{
"page": {
"id": 21,
"wikiid": 19,
"subwikiid": 18,
"groupid": 0,
"userid": 0,
"title": "Home",
"cachedcontent": "(Wrong content here)",
"contentformat": 1,
"caneditpage": true,
"version": 106,
"tags": []
},
"warnings": []
}
In the web page of the correct Wiki page, from the Edit button's link, I can guess the Wiki's ID is 7
instead of 21
, but the ID=7 does not appear in any response. When I use the mod_wiki_get_page_contents
with pageid=7
, it shows the correct content.
My question is: how can I make use of the Moodle API to obtain the ID=7?
Thanks.
From the original response - '21' is the 'course module id' (this is a number that is unique to that activity, regardless of the activity type - e.g. 21 is a wiki in this course, 22 might be a forum instance, 23 might be an assignment, 24 might be another wiki). Under the hood, this is the id of the mdl_course_modules DB table.
'5' is the 'instance id' - this identifies a particular wiki (there can also be an assignment with 'instance id' 5, a forum with 'instance id' 5, etc.). Under the hood, this is the id of the mdl_wiki DB table (or the mdl_assign, or mdl_forum tables, for those activity types).
If you use this 'instance id' (of 5) you can get a list of all the pages within that wiki activity, by calling mod_wiki_get_subwiki_pages
(if there is just 1 subwiki, then the pages for that will be returned, otherwise you may need to specify the user or group within that wiki that you want the pages for).
The response from mod_wiki_get_subwiki_pages
will include the 'id' of each of the pages, which you can then feed into mod_wiki_get_page_contents
, in order to get the content you are looking for.