title: Upload scorm packages in moodle course module using moodle rest api
body: <p>I have already created a course using moodle RestAPI(function name : core_course_create_courses). then i want to upload a scorm package in moodle course module/activity.
  i have write some code for that,this code will create a module in that course. i don't know how to upload scorm package in that course module.</p>
  
  <p>here is my code</p>
  
  <ol>
  <li><p>Add function core_course_create_modules  in lib/db/services.php at line no : 327</p>
  
  <p><code>'core_course_create_modules' =&gt; array(
         'classname' =&gt; 'core_course_external',
         'methodname' =&gt; 'create_modules',
         'classpath' =&gt; 'course/externallib.php',
         'description' =&gt; 'Creates modules in a course',
         'type' =&gt; 'write',
         'capabilities' =&gt; 'moodle/course:manageactivities',
     )</code></p></li>
  <li><p>Add 3 method in Courses/externallib.php file </p></li>
  </ol>
  
  <p>2.1)create_modules_parameters</p>
  
  <pre><code>=&gt; `public static function create_modules_parameters() {
          $courseconfig = get_config('moodlecourse'); //needed for many default values
          return new external_function_parameters(
              array(
                  'courseid' =&gt; new external_value(PARAM_INT, 'ID of the course'),
                  'modules' =&gt; new external_multiple_structure(
                      new external_single_structure(
                          array(
                              'modulename' =&gt; new external_value(PARAM_TEXT, 'Name of the module'),
                              'section' =&gt; new external_value(PARAM_INT, 'Sectionnumber'),
                              'name' =&gt; new external_value(PARAM_TEXT, "Title of the module", VALUE_OPTIONAL),
                              'visible' =&gt; new external_value(PARAM_INT, '1: available to student, 0:not available', VALUE_OPTIONAL),
                              'description' =&gt; new external_value(PARAM_TEXT, 'the new module description', VALUE_OPTIONAL),
                              'descriptionformat' =&gt; new external_format_value(PARAM_INT, 'description', VALUE_DEFAULT),
                              'groupmode' =&gt; new external_value(PARAM_INT, 'no group, separate, visible', VALUE_DEFAULT, $courseconfig-&gt;groupmode),
                              'groupmembersonly' =&gt; new external_value(PARAM_INT, '1: yes, 0: no', VALUE_DEFAULT, 0),
                              'groupingid' =&gt; new external_value(PARAM_INT, 'grouping id',VALUE_DEFAULT, 0)
                          )
                      )
                  )
              )
          );
      }`
  </code></pre>
  
  <p>2.2)    create_modules</p>
  
  <pre><code>`public static function create_modules($courseid, $modules) {
      global $CFG, $DB;
  
      require_once($CFG-&gt;dirroot . "/course/lib.php");
      require_once($CFG-&gt;dirroot . "/course/modlib.php");
  
      $moduleinfo = new stdClass();
      $course = $DB-&gt;get_record('course', array('id'=&gt;$courseid), '*', MUST_EXIST);
  
      // Clean the parameters.
      $params = self::validate_parameters(self::create_modules_parameters(), array('courseid' =&gt; $courseid,'modules' =&gt; $modules));
  
      $context = context_course::instance($course-&gt;id);
      require_capability('moodle/course:manageactivities', $context);
  
      foreach ($params['modules'] as $mod) {
          $module = (object) $mod;
          $moduleobject = $DB-&gt;get_record('modules', array('name'=&gt;$module-&gt;modulename), '*', MUST_EXIST);
  
          if(trim($module-&gt;modulename) == ''){
              throw new invalid_parameter_exception('Invalid module name');
          }
  
          if (!course_allowed_module($course, $module-&gt;modulename)){
              throw new invalid_parameter_exception('Module "'.$module-&gt;modulename.'" is disabled');
          }
  
          if(is_null($module-&gt;visible)){
              $module-&gt;visible = 1;
          }
  
          if(is_null($module-&gt;description)){
              $module-&gt;description = '';
          }
  
          if(!is_null($module-&gt;name) &amp;&amp; trim($module-&gt;name) != ''){
              $moduleinfo-&gt;name = $module-&gt;name;
          }
  
          $moduleinfo-&gt;modulename = $module-&gt;modulename;
  
          $moduleinfo-&gt;visible = $module-&gt;visible;
          $moduleinfo-&gt;course = $courseid;
          $moduleinfo-&gt;section = $module-&gt;section;
          $moduleinfo-&gt;introeditor = array('text' =&gt; $module-&gt;description, 'format' =&gt; $module-&gt;descriptionformat, 'itemid' =&gt; 0);
          $moduleinfo-&gt;quizpassword = '';
          $moduleinfo-&gt;groupmode = $module-&gt;groupmode;
          $moduleinfo-&gt;groupmembersonly = $module-&gt;groupmembersonly;
          $moduleinfo-&gt;groupingid = $module-&gt;groupingid;
          $retVal = create_module($moduleinfo);
  
          $result[] = array('id'=&gt;$retVal-&gt;id);
      }
      return $result;
  }`
  
  2.3)create_modules_returns
  `public static function create_modules_returns() {
      return new external_multiple_structure(
          new external_single_structure(
              array(
                  'id' =&gt; new external_value(PARAM_INT, 'new module id')
              )
          )
      );
  }`
  </code></pre>
  
  <p>Parameters to call function </p>
  
  <pre><code>$module['courseid'] = 1; //course id
      $module['modules'][] = array(
      "section" =&gt; 2,//PARAM_INT, 'Sectionnumber'
      "modulename" =&gt; "scorm",//PARAM_TEXT, 'Name of the module'
      "name" =&gt; "Testing1",// OPTIONAL PARAM_TEXT, "Title of the module",
      "visible" =&gt; 1,// OPTIONAL PARAM_INT, '1: available to student, 0:not available',
      "description"=&gt;"testing module using rest api", // OPTIONAL PARAM_TEXT, 'the new module description',
      "descriptionformat"=&gt;1,//PARAM_INT, 'description', VALUE_DEFAULT
      //"groupmode" =&gt; "",//PARAM_INT, 'no group, separate, visible', VALUE_DEFAULT, $courseconfig-&gt;groupmode
      //"groupmembersonly" =&gt; "",//PARAM_INT, '1: yes, 0: no', VALUE_DEFAULT, 0
      //"groupingid" =&gt; "",//PARAM_INT, 'grouping id',VALUE_DEFAULT, 0
    );
  </code></pre>
  
  <p>as per above code ,
   its take name field as a scorm packages, in the admin side its display name as a scorm, when i was click on that its display errors:</p>
  
  <p><a href="https://i.stack.imgur.com/LKetw.png" rel="nofollow noreferrer">screenshot for error</a></p>
  
  <p>so, i don't know how to upload scorm package in course module using moodle Rest api, how can i do ?</p>
  
  <p>Thank you.</p>