Including role enrolments in core_course_duplicate_course

Including role enrolments in core_course_duplicate_course

by Alexander Lebeth -
Number of replies: 0

I'm trying to duplicate courses via webservice core_course_duplicate_course. The script below shows an example of how course duplicates can be created with and without user data. While the option to include user data is possible with webservice, I just can't figure out how to make the webservice including the role enrolments in the duplicate (see attached screenshot of the UI where you're obviously able to select the roles for including). How can I pass the option for role enrolment? I want to include only some roles (teachers), not all.

Since I'm new to REST API of moodle, any help is much appreciated!


#!/bin/bash
API="http://10.1.1.13/sm/webservice/rest/server.php"    # WS entry point.
COURSEID=25 # Course to duplicated.
CATEGORYID=1 # Category to duplicate to.
TOKEN="490b48f8cd71e88a37fa70cc6eff3fb2" # WS Token. # SCRIPT STARTS HERE.
SUFFIX=`date +"%s"` echo "Duplicate without user data" SHORTNAME="Duplicated${COURSEID}_NODATA_${SUFFIX}"
curl $API\
-d moodlewsrestformat=json\
-d wstoken=$TOKEN\
-d wsfunction=core_course_duplicate_course\
-d courseid=$COURSEID\
-d fullname="Duplicated $COURSEID (without user data) - $SUFFIX"\
-d shortname="$SHORTNAME"\
-d categoryid=$CATEGORYID\
-d 'options[0][name]=users'\
-d 'options[0][value]=0' echo
echo "Duplicate with user data" SHORTNAME="Duplicated${COURSEID}_${SUFFIX}"
curl $API\
-d moodlewsrestformat=json\
-d wstoken=$TOKEN\
-d wsfunction=core_course_duplicate_course\
-d courseid=$COURSEID\
-d fullname="Duplicated $COURSEID (with user data) - $SUFFIX"\
-d shortname="$SHORTNAME"\
-d categoryid=$CATEGORYID\
-d 'options[0][name]=users'\
-d 'options[0][value]=1' echo


Average of ratings: -