webservices for Assignment

webservices for Assignment

by Laura Celentano -
Number of replies: 4

Moodle 2.6 introduces new webservices for Assignment module and I'm trying to use them, following API documentation.

The problem is that I don't know how to retrieve some of the input parameters required, for example mod_assign_save_submission requires the plugindata structure, containing information about draft area, how can I get them? 

In https://tracker.moodle.org/browse/MDL-37148 I have read about mod_assign_prepare_submission function, but there is not such function in current Moodle version, is there any other way to retrieve this kind of information?

Thanks in advance.

Average of ratings: -
In reply to Laura Celentano

Re: webservices for Assignment

by Laura Celentano -

Anyone can give me some advice? I just would like to understand if I have to give up on these functions and try to create my own webservices.

Thanks.

In reply to Laura Celentano

Re: webservices for Assignment

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 
  • 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
    Call mod_assign_save_submission, using as input parameter the file id  and assignment id retrieved previously
    • 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

In reply to Laura Celentano

Re: webservices for Assignment

by Andy Sayler -

Hi Laura,

What parameters did you supply to 'core_files_upload' to make it work?

I'm currently trying to do something like this, but when I call 'core_file_upload' with the following params, I get an error:

Params:

itemid = 1,
contextid = 1,
filepath = /
filearea = private
component = user
filename = test1.txt
filecontent = VGhpcyBpcyBhIHRlc3QK (base64)

Response:

{'errorcode': 'nofile', 'exception': 'moodle_exception', 'message': 'File not specified'}

I'm also not really sure what to use for teh contextid. I'm just trying to push up soem files to a user's private file storage to start.

Thoughts?