Hello, I'm having a bit of an issue with getting my requests to work with web services. I've created a custom service that has core_user_create_users function in the admin area, have the token and everything, but the request returns nothing. I'm using the demo code for clients from https://github.com/moodlehq/sample-ws-clients but am having no luck. All I'm trying to do is create a user, which is what it looks like the sample web service clients (REST and SOAP) are doing as well. From what I can tell, the user that I'm using the access token for has the proper capabilities in Moodle (create user, update user, delete user as well as a few others for good measure). My biggest problem is that I'm just getting an empty string from the calls, no errors or anything, and I'm not sure which direction to start looking. Any direction or help you might be able to provide would be amazing. Thanks!
Both REST and SOAP calls to webservice return nothing
Re: REST API for Quiz-Password
I am also having the same problem.
But I am not getting, how to change the code..
Could you please give me step by step instructions, if possible code also!!!
Thanking
Re: How to get JSON from REST Web API
and if you want the same in CSV, just paste that URL into json-csv.com
Web service image profile
Hi,
someone know how can i insert an image to an existing user profile with web service?
Thanks.
How to Use Moodle web services (api) in our own iOS app
I want to use moodle web services (api) in my own ios app. I want to prepare my own iOS app using Moodle web services. I want to consume moodle webservices for my own ios app.
How can I use its web services (api) in my own app? what its request Format eg. SOAP or any other? what are requesting links?.
If there is any tutorial or sample Project or any documentation which explain me everything about usage of Moodle web services would very Helpful. Thanks
Trying to Make mod_assign_save_grade Work
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).
Re: Trying to Make mod_assign_save_grade Work
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.
Re: webservices for Assignment
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?
Re: Authentication on external website with Moodle user
I'm using Moodle as an authentication backend for a Python-flask service I'm building. The basic gist is:
How to login using Moodle User from REST Web Service
Hi,
I am newbie to Moodle.
What I want to do is basically using REST Web service I want to access Moodle contents and for that first thing I want to do is to logged in into Moodle and also wants to logout using REST API.
How can I do this ?
Can anybody please help me with this ?
Webservices change from 2.5 to 2.7?
Hi I am grasping at straws and trying to get the old TurnItIn.com Basic plugin to work on 2.7. Currently it fails at assignment creation with the error
P { margin-bottom: 0.08in; }A:link { }
Unable to complete Moodle webservices call. 404 Not Found
2.7
* All webservice server.php and simpleserver.php scripts must define('WS_SERVER', true)
before including config.php file.
In the plugin I see a ws folder with a dispatcher.php which has a line
require_once("../../../../../config.php");
Should I try adding the line define('WS_SERVER', true) before the require_once?
Any other ideas or changes between web services in 2.7 compared to 2.5?
Permissions not working as expected through REST API
Hi,
I am trying to use REST API to create users in Moodle.
I am getting token for a user which has "Student" role from below URL and able to get that token
and now I am trying to create user through this token
http://54.191.197.43/moodle/webservice/rest/server.php/?token=mytoken&wsfunction=moodle_user_create_user
but it still allows me to create user even if I set "Prohibit" for create user permission for "Student" role.
Can someone help me with this ?
Why permission check is not happening in this scenario ?
Re: Can Moodle users be Web Service users?
I am also facing same issue like for role "Student" I have set "Create User" permission "Prohibit" but still using token I am able to create user from student credentials throught REST API.
And we can only select one capability for single external service.
so token we get at login/token.php for service1, can we use it to call service2 ?
Can you help me with this issue ?
Re: Webservices change from 2.5 to 2.7?
I added the define('WS_SERVER', true) in dispatcher.php but no luck. I can get the plugin to work with existing assignments: rosters can sync between Moodle and TurnItIn, students can submit assignments, teachers can grade assignments. However, when I try to create or modify an assignment it throws the webservices call error. So why would webservices work for some calls and say, not found in other calls? And why would the plugin work in 2.5 and 2.6 and not in 2.7?
Re: Invalid parameter in core_get_string call
I discovered this issue as well.
The problem is a mismatch between the external function parameters returned by get_string_parameters() and the actual method signature of get_string: get_string does not have a lang parameter. However the definition below specifies one (see below).
public static function get_string_parameters() {
return new external_function_parameters(
array('stringid' => new external_value(PARAM_STRINGID, 'string identifier'),
'component' => new external_value(PARAM_COMPONENT,'component', VALUE_DEFAULT, 'moodle'),
'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),
'stringparams' => new external_multiple_structure (
new external_single_structure(array(
'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
- if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
'value' => new external_value(PARAM_TEXT,'param value'))),
'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
)
)
);
}
I will do as Bill suggested, ie comment out the 'lang' parameter definition from the get_string web service call. However that only addresses this issue temporarily ( and only for me .. and Bill ).
Has this been resolved in a later version of Moodle? I too am using version 2.6.
I'm not a PHP developer (I spend most of my time in java) and I'm more used to stronger typed languages and so not at all used to this type of scenario. Nonetheless I have a suggestion that could help guard against this parameter/mismatch and create a more tightly checked system.
Is it possible to write a unit (or integration) test that iterates through all the externally defined functions (SELECT * FROM mdl_external_functions) and validates that all the function parameter definitions actually match up with the function signatures. Not being a PHP dev I'm not sure if you can extract that sort of meta data. Anyhow, just a thought. No idea if this is doable.
Re: enrol_manual_enrol_users limit
Anyone have any insight on this. I setup a test server where I was sending 22,000 enrolments through the API. It seemed that when I sent that it would only process between 150-300 updates/inserts before it would quit. So I broke the enrolment calls into 200 enrolment chunks and was able to get all the enrollments to process. Is the API script timing out? If it is how can I increase it?
Re: How to get all assignments for a course.
Having the same problem - did you ever find a solution?
Thanks
Re: mod_forum_get_discussion doesn't return discussions content
Did you had any success with that?
We're having the same problem here...
We just can't find a way to get the full message from the discussions... Only the subjects.
Thanks!
Ability to fetch Course Summary file via core_course_get_courses webservice
I have been trying to fetch course summary file through web-service externally.
i am using "core_course_get_courses" but it doesn't return course summary file. See the below returned information.
Can we have this ability inside this web-service or is there any other option for this? can anyone suggest a possibility to get course summary files externally using webservices?
Return course details
Arguments
options (Default to "Array ")
options - operator OR is used
General structure
Default to "Array
(
)
" //options - operator OR is used
object {
ids Optional //List of course id. If empty return all courses
except front page course.
list of (
int //Course id
)}
XML-RPC (PHP structure)
[options] =>
Array
(
[ids] =>
Array
(
[0] => int
)
)
REST (POST parameters)
options[ids][0]= int
Response
General structure
list of (
//course
object {
id int //course id
shortname string //course short name
categoryid int //category id
categorysortorder int Optional //sort order into the category
fullname string //full name
idnumber string Optional //id number
summary string //summary
summaryformat int //summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN)
format string //course format: weeks, topics, social, site,..
showgrades int Optional //1 if grades are shown, otherwise 0
newsitems int Optional //number of recent items appearing on the course page
startdate int //timestamp when the course start
numsections int Optional //(deprecated, use courseformatoptions) number of weeks/topics
maxbytes int Optional //largest size of file that can be uploaded into the course
showreports int Optional //are activity report shown (yes = 1, no =0)
visible int Optional //1: available to student, 0:not available
hiddensections int Optional //(deprecated, use courseformatoptions) How the hidden sections in the course are displayed to students
groupmode int Optional //no group, separate, visible
groupmodeforce int Optional //1: yes, 0: no
defaultgroupingid int Optional //default grouping id
timecreated int Optional //timestamp when the course have been created
timemodified int Optional //timestamp when the course have been modified
enablecompletion int Optional //Enabled, control via completion and activity settings. Disbaled,
not shown in activity settings.
completionnotify int Optional //1: yes 0: no
lang string Optional //forced course language
forcetheme string Optional //name of the force theme
courseformatoptions Optional //additional options for particular course format
list of (
object {
name string //course format option name
value string //course format option value
}
)}
)
Re: Ability to fetch Course Summary file via core_course_get_courses webservice
Can anyone help help us with this please?