by Laura Celentano.
This is how I'm using the functions above:
- First upload the file draft using core_files_upload, something like:
- http://mymoodle/moodle/webservice/rest/server.php?moodlewsrestformat=json&wstoken=tokenvalue&wsfunction=core_files_upload&contextid=21&component=user&filearea=draft&itemid=0&filepath=/&filename=test.pdf. In its response there is the file id.
- the problem is that there's not a web service for getting context id, we need to work on it
- http://mymoodle/moodle/webservice/rest/server.php?moodlewsrestformat=json&wstoken=tokenvalue&wsfunction=core_files_upload&contextid=21&component=user&filearea=draft&itemid=0&filepath=/&filename=test.pdf. In its response there is the file id.
- Retrieve assignments id calling mod_assign_get_assignments
- http://mymoodle/moodle/webservice/rest/server.php?wsfunction=mod_assign_get_assignments&moodlewsrestformat=json&wstoken=tokenvalue&courseids[0]=2
- http://mymoodle/moodle/webservice/rest/server.php?wsfunction=mod_assign_save_submission&moodlewsrestformat=json&wstoken=tokenvalue&assignmentid=1&plugindata[onlinetext_editor][text]=sometext&plugindata[onlinetext_editor][format]=1&plugindata[onlinetext_editor][itemid]=draftfileid&plugindata[files_filemanager]=draftfileid
- if required (by assignment settings) call mod_assign_submit_for_grading
- http://mymoodle/moodle/webservice/rest/server.php?wsfunction=mod_assign_submit_for_grading&moodlewsrestformat=json&wstoken=tokenvalue&assignmentid=1&acceptsubmissionstatement=1
I don't know if this is to best way to achieve assignment submission, I hope that this can be helpful for someone