Web Service Token or Parameter problem

Web Service Token or Parameter problem

by Chris C -
Number of replies: 5

I have an ASP.NET web application and a Moodle 2.2 web application set up in my test environment. I am trying to query a Moodle web service (core_user_get_users_by_id) from my ASP.NET app, I get this error:

<?xml version="1.0" encoding="UTF-8" ?> <EXCEPTION class="webservice_access_exception"> <MESSAGE>Access control exception</MESSAGE> <DEBUGINFO>Invalid token - token not found</DEBUGINFO> </EXCEPTION>

I have created the token, and associated it with my wsuser (web services user account) in Moodle, and I have run the web service successfully through Moodle's web service test client.

I have obtained a token via the admin interface, and also via login/token.php (as referenced here: http://docs.moodle.org/dev/Creating_a_web_service_client#How_to_get_a_user_token). Interestingly, I get different values. I also set up the shortname value for the web service (directly in the DB because there is no field in the Moodle 2.2 website for that value).

I'm guessing that the QueryString I am posting to the Moodle web service is incorrect. I've tried all combinations of the the following six parameters without success:

//Possible QueryString parameters for call to webservice "core_user_get_users_by_id".
"?method=core_user_get_users_by_id" +
"&token=" + token +
"&wstoken=" + token + // wstoken is used by the Moodle test client, but token is correct per documentation.
"&username=" + username + // my "web services user" in moodle.
"&servicename=view_user_details" + // view_user_details is the webservice shortname value I set.
"&userids[0]=" + userid;

The last parameter name, userids[0], I got by using the input parameter name used by Moodle's web service test client's form. I obviously need to pass a userid for the query, but I cannot find a clear example in any of the Moodle docs.


I would be grateful for any help on this problem.

Average of ratings: -
In reply to Chris C

Re: Web Service Token or Parameter problem

by Sergio Hernández -
In reply to Sergio Hernández

Re: Web Service Token or Parameter problem

by Chris C -

Thank you.  I had seen that, and have gone through the entire list, and everything is as it should be.  I have turned on debugging, and that is how I was able to receive the <DEBUGINFO> in the XML response from my Moodle site.

You'll see in my original message that I am wondering about the QueryString parameter names I am using in my attempt to invoke the web service.  I've found these names by looking through the Moodle PHP, but I don't see them clearly in any of the docmentation.  I just can believe they are not documented in the instructions or community discussions on using the web service.  Since they are not documented, I feel that maybe I am missing something very basic.

In reply to Chris C

Re: Web Service Token or Parameter problem

by Sergio Hernández -

Hi

I used this to call a webservice:

/webservice/rest/server.php?wstoken=1cfc5a5676b281fe17d4a3419453fd93 &wsfunction=core_webservice_get_site_info&moodlewsrestformat=json

I got the token using:

moodle/login/token.php?username=test&password=Test@1977&service=MWW

 

Regards

Sergio

Average of ratings: Useful (1)
In reply to Sergio Hernández

Re: Web Service Token or Parameter problem

by Chris C -

Thank you, Sergio!

My parameter name "method" should have been "wsfunction" instead.  It works now.  These are the parameters that work for me:

"?wsfunction=core_user_get_users_by_id" +
"&wstoken=" + token + 
"&userids[0]=" + userid;

P.S. "&moodlewsrestformat=json" also works, but not needed for my purposes.

In reply to Chris C

Re: Web Service Token or Parameter problem

by roc mehra -

I have the same problem can you please tell me. What will the appropriate parameter for my web service