moodlemoodle-apimoodle-mobile

Moodle get course information + all lessons through Api


I am trying to collect all information related to Moodle course (course + lessons) Using Moodle Api I got the course information, but gets only some basic information, I want course details and its lessons (created under course)

    Eg :  var domainname = 'http://<server URL>/moodle'; 
var token = 'df337369637c692303d903f8cacf1eb0'; 
var functionname = 'core_course_get_courses'; 
var serverurl = domainname + '/webservice/rest/server.php' ; 
var data = {
            wstoken: token,
            wsfunction: functionname,
            moodlewsrestformat: 'json'              
                } var response = $.ajax(
               {   type: 'GET',
                   data: data,
                   url: serverurl
               }
              );

And the output looks like

{"id":2,"shortname":"IV Support Queries","categoryid":1,"categorysortorder":10001,"fullname":"IV Support Queries","displayname":"IV Support Queries","idnumber":"","summary":"<p>IV Support Queries Desc<br \/><\/p>","summaryformat":1,"format":"topics","showgrades":1,"newsitems":5,"startdate":1479168000,"numsections":5,"maxbytes":0,"showreports":0,"visible":1,"hiddensections":1,"groupmode":0,"groupmodeforce":0,"defaultgroupingid":0,"timecreated":1479127227,"timemodified":1479198758,"enablecompletion":0,"completionnotify":0,"lang":"","forcetheme":"","courseformatoptions":[{"name":"numsections","value":5},{"name":"hiddensections","value":1},{"name":"coursedisplay","value":1}]}

I want the lesson details created under course .How can i get the information through Api . Thanks


Solution

  • Using function

    "core_course_get_contents"

    getting all the informations related with course.

    var domainname = 'http://<server URL>/moodle'; 
    var token = 'df337369637c692303d903f8cacf1eb0'; 
    var functionname = 'core_course_get_contents'; 
    var serverurl = domainname + '/webservice/rest/server.php' ; 
    var data = {
                wstoken: token,
                wsfunction: functionname,
                moodlewsrestformat: 'json' ,
                courseid: 2 //Retrieve results based on course Id 2            
               } 
    var response = $.ajax(
                   {   type: 'GET',
                       data: data,
                       url: serverurl
                   }
                  );
    

    Thanks