Trying to Make mod_assign_save_grade Work

Trying to Make mod_assign_save_grade Work

by Andy Sayler -
Number of replies: 1

Hi All,

I'm trying to get calls to the mod_assign_save_grade endpoint to work using REST/JSON. Other endpoints are working fine (e.g. mod_assign_get_grades), but I can't seem to get anything but the terribly unhelpful "invalid_parameter_excpetion" back from the mod_assign_save_grade endpoint.

Call

curl -X GET 'https://mymoodle.edu/webservice/rest/server.php?
wstoken=<token>&moodlewsrestformat=json&wsfunction=mod_assign_save_grade&
assignmentid=1&userid=4&grade=3&attemptnumber=-1&addattempt=0&workflowstate=graded&applytoall=0'
Response
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected"}

I am providing all of the  arguments marked as required in the docs. Anyone see the issue?

Also, a few points that aren't clear from the docs:

  • What is the 'addattempt' parameter for? What should it be set to if you don't care/aren't using manual attempts?
  • What is the "workflowstate" parameter for? What should it be set to if not using grading workflows?
  • Does the 'applytoall' parameter have any bearing if you're not using groups?

Also, is there any logging on the Moodle-server side of things that will provide more details about why WS requests get rejected with the generic "invalid_paramter_excpetion"? There must be better ways to inform developers about what's going wrong...

Anyone have any ideas or can point me at soem working mod_assign_save_grade code (I can't find any uses on github)? Despite teh CURL example above, I'm actually trying to hit this endpoint via a python-requests script. But I get the same result via curl.

I'm on a git pull of Moodle 2.7.1+ (Build: 20140717).

Average of ratings: -
In reply to Andy Sayler

Re: Trying to Make mod_assign_save_grade Work

by Andy Sayler -

So I ended up getting this to work. It turns out the plugin parameters are required (even though they aren't marked as such in the docs):

E.g.

curl -X GET 'https://mymoodle.edu/webservice/rest/server.php?
wstoken=<token>&moodlewsrestformat=json&wsfunction=mod_assign_save_grade&
assignmentid=1&userid=4&grade=3&attemptnumber=-1&addattempt=0&workflowstate=graded&applytoall=0'&
plugindata%5Bassignfeedbackcomments_editor%5D%5Btext%5D=test&
plugindata%5Bassignfeedbackcomments_editor%5D%5Bformat%5D=1&plugindata%5Bfiles_filemanager%5D=0'

Which still poses the questions:

  • Should these parameters be marked as required if you get a "invalid parameter error" without them?
  • Can anyone tell me what the 'plugindata[assignfeedbackcomments_editor][format]' parameter does?

And it would still be great to know if there are more detailed debugging logs for incoming failed WS calls anywhere.

Thanks!

P.S. My Python wrapper code can be found at https://github.com/asayler/moodle-ws-python/blob/master/ws.py.