REST protocol (with JSON/XML payload support)
Maintained by
Owen Barritt
REST webservice protocol based on the standard core REST webservice, but with added support for JSON & XML payloads
and supports using HTTP ACCEPTS headers for determining response format.
Comments
Comments are no longer open for new posts. Existing comments remain available to read.
I tried this json structure too but no luck {"Courses":[{"fullname":"Bulk insert","shortname":"short bulk","categoryid":1}]}
How can i format the json object to post, because call core_course_create_courses method for create course, my json structure was [{"fullname":"Bulk insert","shortname":"short bulk","categoryid":1}]
But i got the error link {"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected"}
Could you please suggest what kind of structure i need to send course creation
Until it's fixed, to get it to work the the REST protocol (with JSON/XML support) needs to be enabled and the webservice user must have the webservice/rest:use permission set to 'allowed'.
The core REST protocol doesn't need to be enabled though and the webservice/restjson:use permission currently doesn't do anything (although it should do instead of the webservice/rest:use one when it's fixed).
The fields are missing error sounds like your not sending the parameters expected by the function you're calling. I'd need some idea of the JSON your sending to look into this as all the JSON I've used has been accepted by the webservice without issue, so I can't recreate this issue at the moment.
<?xml version="1.0" encoding="UTF-8" ?>invalidparameterInvalid parameter value detectedNo response types acceptable
For the following curl request:
curl 'http://localhost/moodle/webservice/restjson/server.php?wstoken=26255e91cb715c25cc39ff9cee9d8843&wsfunction=core_user_get_users_by_field' -X POST -d '{
"field":"id",
"values":["2"]
}' -H 'Content-Type: application/json'
I noticed this DEBUGINFO error message is generated in the restjson/locallib.php so I will try to debug that myself (unless you straight away know whats going wrong).
curl 'http://localhost/moodle/webservice/rest/server.php?wstoken=&wsfunction=core_user_get_users_by_field&moodlewsrestformat=json' -X POST -d '{
"field": "id",
"values": [2]
}' -H 'Content-Type: application/json'
The response is 403 'Forbidden'.
I checked my apache logs and its giving me the following [Thu Feb 18 17:18:16.057213 2016] [:error] [pid 6903] [client 127.0.0.1:39224] Debugging: The server died because the web services or the REST protocol are not enable in \n* line 39 of /webservice/rest/server.php: call to debugging()\n
For some reason it is referring to webservice/rest/server.php instead of webservice/restjson/server.php.
When both protocols / permissions are enabled / allowed then it does not seem to accept my JSON as input, the response is that fields are missing.
Can you access the JSON/XML support version if both protocols are enabled and both permissions are set to allowed?