What is
error/moodle/invalidrecord
Re: Why does a category idnumber return null?
Bump
How to retrieve module tags through WEB API?
How is it possible to retrieve tags applied to a module through the WEB API?
Re: How to retrieve module tags through WEB API?
Is there a way to access course summary files through the web API?
Hi everyone
Hope we can have a good time and try to work really hard
Re: Moodle core_user_create_users Access control exception
Hi
For the web-service user in moodle did you assign the right permissions to create users:
require_capability('moodle/user:create', $context);Let us know!
Regards
Re: Problems with webservice access
Unfortunately, I do not have an answer to your question, but another question. Is it possible to access Moodle's APIs as a teacher and not a site administrator?
Re: Problems with webservice access
Hi Ghislain,
Yes, it is possible to access Moodle's APIs like Web Services as a teacher. For web services just create a token for the user for which you want to create access capability. you can create a token from Site Administration > Plugins > Webservices > Manage Tokens or hit http://example.com/admin/settings.php?section=webservicetokens.
Regards,
Mayank Tyagi
Re: Problems with webservice access
Thank you very much for your response. Actually, I am a teacher at a university and after searching for a few days, I was not able to find out how to access Site Administration. My best best is that only the administration of the university has such an access. If that is the case, does that mean that I need to ask them to create a token for me so I can access the APIs?
Sincere thanks.
Re: How to retrieve module tags through WEB API?
Bump
Cannot get course list on web services
Hi guys, I am new to moodle and I am trying to retrieve a list of courses via the web service. I followed all the instructions on enabling the web services, creating a user, roles, services, permissions, adding functions, etc.
I am calling:
http://[MOODLE_URL]/webservice/rest/server.php?wstoken=[TOKEN]&moodlewsrestformat=json&wsfunction=core_course_get_courses
But getting back
{"exception": "moodle_exception","errorcode": "errorcoursecontextnotvalid","message": "You cannot execute functions in the course context (course id:2). The context error message was: Course or activity not accessible."}
I am sure it is just some kind of permission or setting somewhere, can any point me in the correct direction?
Much appreciated
Re: Cannot get course list on web services
I changed the function name to core_course_get_courses_by_field and I am getting data back.
In case anyone else has this issue...
Issued with using the REST api
Hi, I have been using the following string to access the REST api of our moodle install
/webservice/rest/server.php/?wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=5078&wstoken=MYTOKEN&options[0][name]=userfields&options[0][value]=id&options[1][name]=userfields&options[1][value]=fullname&options[2][name]=userfields&options[2][value]=email&options[3][name]=userfields&options[3][value]=username&options[4][name]=userfields&options[4][value]=idnumber
This successfully pumps out some json formatted data like so
[{"id":1600,"username":"name1","fullname":"A Stark","email":"a.stark@email.uk","idnumber":"123456"},{"id":2019,"username":"name2","fullname":"B Stark","email":"b.stark@email.uk","idnumber":"123457"}
I would also like to get some roles to allow me to better filter the results, I have tried adding
&options[5][name]=userfield&options[5][value]=roles
To the end of the string but this does not give any additional information. Any advice on how I messed up?
How do we fetch the name of each categoryid returned by gradereport_user_get_grade_items?
The gradereport_user_get_grade_items API call returns a categoryid field, but does not return the "full name" of the category. The name associated with the categoryid is found in the mdl_grade_categories table.
Is there an API call that would allow fetching the "full name" associated with the categories? It appears that there is not. But perhaps I have overlooked it?
See associated JIRA ticket https://tracker.moodle.org/browse/MDL-64399.
Webservice POST error: Invalid token - token not found
I have enabled the web services, added the service, and added authorised users. With the token, I have the below URL, which I used in Postman to send some create course parameters.
However I am getting below error:
{
"exception": "moodle_exception",
"errorcode": "invalidtoken",
"message": "Invalid token - token not found"
}
The token is from the right user (admin), and previously the same test was successful.
What am i missing here?
Do i need to have a Restful plugin too?
Webservice and core function parameters
I am running moodle 3.4 on centos, and will be implementing webservices using Rest API for our server.
I have listed out the core functions that we will be using, however we seem to need some additional fields such as Cohort Start/End Date or Employer ID/Employer name.
In the DB I can add these columns to store these data but I am wondering how can I tweak the REST parameters to POST/GET these parameters?
Web Service
I have created external web service in moodle 3.6.1 and added one function mod_quiz_start_attempt in external service.
But this service access by only admin when any other user try to access this service they got following error.
{
"exception": "moodle_quiz_exception",
"errorcode": "notyourattempt",
"message": "This is not your attempt!"
}
As a admin if I want to allow other users to attempt the quiz using web service API then is there any possible ways to do this?
Re: Web Service
Hi Nirav,
you need to authenticate the actual user willing to attend the attempt: you cannot start an attempt as an admin since it will be the attempt of that user.
HTH,
Matteo
startdate FROM mdl_user_enrolments
Hello!
Im trying to get data from table mdl_user_enrolments through web services. What i checked, this web service /core_enrol_get_users_courses/ is getting me pretty much required data, but i am missing some important columns like 'timestart'. I am getting startdate and enddate of course, but i want to get timestart of enrolment. It is possible from different webservice, or it is not? I cant find any usefull web service for this and i dont want to connect to moodle database from external app.
For example what i need:
SQL Query: SELECT timestart FROM mdl_user_enrolments WHERE userid = xy;
Thanks for help, much appreciated.
JK
Moodle 3.6.1 (Build: 20181205)
Re: Webservice and core function parameters
Hey Karishma,
If you want to add rest parameter for GET/POST you can do it by this.
http://example.com/webservice/rest/server.php?wstoken=4d58eb874d279fd220e9&wsfunction=location_webservices_create_variant&moodlewsrestformat=json&group_idnumber=97&name=Full Week&course_idnumber=toefl&location_idnumber=99