1

I have to list all the attachments of a discussion in a course. I don't know how to retrieve all the attachments URLs in a forum/discussion in Moodle LMS.

My code is in c# and usually, I call the Moodle REST API as http://localhost:8077/webservice/rest/server.php?wstoken=11e2d8b7f8e21ca1804e41e9cac5a812&wsfunction=core_course_get_contents&courseid=4&moodlewsrestformat=json and I can get the fileurl for the course files.

Likewise, I would like to retrieve forum/discussion files but I don't see any fileurl or something similar. I only see the response as below:

[

    {

        "id": 22,

        "name": "General",

        "visible": 1,

        "summary": "",

        "summaryformat": 1,

        "section": 0,

        "hiddenbynumsections": 0,

        "uservisible": true,

        "modules": []

    },

    {

        "id": 23,

        "name": "Introduction",

        "visible": 1,

        "summary": "",

        "summaryformat": 1,

        "section": 1,

        "hiddenbynumsections": 0,

        "uservisible": true,

        "modules": [           

            {

                "id": 46,

                "url": "http://localhost:8077/mod/resource/view.php?id=46",

                "name": "Everest (.txt)",

                "instance": 24,

                "contextid": 102,

                "visible": 1,

                "uservisible": true,

                "visibleoncoursepage": 1,

                "modicon": "http://localhost:8077/theme/image.php/boost/core/1613571924/f/text-24",

                "modname": "resource",

                "modplural": "Files",

                "indent": 0,

                "onclick": "",

                "afterlink": null,

                "customdata": "\"a:1:{s:10:\\\"printintro\\\";i:1;}\"",

                "noviewlink": false,

                "completion": 1,

                "completiondata": {

                    "state": 0,

                    "timecompleted": 0,

                    "overrideby": null,

                    "valueused": false

                },

                "contents": [

                    {

                        "type": "file",

                        "filename": "Everest.txt",

                        "filepath": "/",

                        "filesize": 935,

                        "fileurl": "http://localhost:8077/webservice/pluginfile.php/102/mod_resource/content/1/Everest.txt?forcedownload=1",

                        "timecreated": 1621949734,

                        "timemodified": 1621949744,

                        "sortorder": 1,

                        "mimetype": "text/plain",

                        "isexternalfile": false,

                        "userid": 2,

                        "author": "DP Bhatt",

                        "license": "unknown"

                    }

                ],

                "contentsinfo": {

                    "filescount": 1,

                    "filessize": 935,

                    "lastmodified": 1621949744,

                    "mimetypes": [

                        "text/plain"

                    ],

                    "repositorytype": ""

                }

            },

            {

                "id": 47,

                "url": "http://localhost:8077/mod/forum/view.php?id=47",

                "name": "Forum",

                "instance": 5,

                "contextid": 112,

                "visible": 1,

                "uservisible": true,

                "visibleoncoursepage": 1,

                "modicon": "http://localhost:8077/theme/image.php/boost/forum/1613571924/icon",

                "modname": "forum",

                "modplural": "Forums",

                "indent": 0,

                "onclick": "",

                "afterlink": null,

                "customdata": "\"\"",

                "noviewlink": false,

                "completion": 1,

                "completiondata": {

                    "state": 0,

                    "timecompleted": 0,

                    "overrideby": null,

                    "valueused": false

                }

            }

        ]

    }

]

It would be great if someone guides me on the right path. Thank you very much in advance.

Simant
  • 3,142
  • 4
  • 32
  • 61

0 Answers0