Web services

having trouble with web services in Moodle 2.0

 
 
Picture of Jamie Pratt
having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writers
Am having some difficulties with web services in the latest version of Moodle 2.0.

Not sure if I'm doing something wrong but no services are showing up but the group related services through the test client.

And using simple authentication or a token am getting a message 'Access control exception'.

I followed the instructions in the system settings to set up capabilities etc.

Are the web services currently considered stable?

Guess I will explore some more.
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Hi Jamie,
these are very good tests. Many exceptions thrown by web services are labelled: 'Access control exception'
However they are all thrown with an additional message. This other message could be unclear. Can you tell me if you see this additional message and what it is?
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
The web services should be pretty stable so yes you can test them.
Thank you smile
 
Average of ratings: -
Ken's pic
Re: having trouble with web services in Moodle 2.0
 

Hi Jerome,

I'm having some difficulty too in getting started testing the webservices.  When I run the testclient.php, an exception is thrown and displays this message:


SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'http://localhost/gnulms/webservice/soap/simpleserver.php?wsusername=admin&wspassword=xxx&wsdl=1'

In the initial form I enter:

Authentication method: Simple
Protocol: Soap
Function: moodle_group_get_course_groups

and the second form I enter the admin, password, and courseid.

I must be missing something - any ideas on what it might be?

Thanks

 
Average of ratings: -
Ken's pic
Re: having trouble with web services in Moodle 2.0
 
Hi Jerome,

Looks like I'm getting the 'Access control exception' after all as well. The full error message I get back when running testclient.php is:

SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'http://localhost/gnulms/webservice/soap/simpleserver.php?wsusername=admin&wspassword=xxx&wsdl=1' in D:\WAMP\htdocs\gnulms\lib\zend\Zend\Soap\Client\Common.php:51
Stack trace:
#0 D:\WAMP\htdocs\gnulms\lib\zend\Zend\Soap\Client\Common.php(51): SoapClient->SoapClient('http://localhos....', Array)
#1 D:\WAMP\htdocs\gnulms\lib\zend\Zend\Soap\Client.php(974): Zend_Soap_Client_Common->__construct(Array, 'http://localhos....', Array)
#2 D:\WAMP\htdocs\gnulms\lib\zend\Zend\Soap\Client.php(1130): Zend_Soap_Client->_initSoapClientObject()
#3 D:\WAMP\htdocs\gnulms\lib\zend\Zend\Soap\Client.php(1054): Zend_Soap_Client->getSoapClient()
#4 D:\WAMP\htdocs\gnulms\webservice\soap\locallib.php(152): Zend_Soap_Client->__call('moodle_group_ge...', Array)
#5 D:\WAMP\htdocs\gnulms\webservice\testclient.php(134): webservice_soap_test_client->simpletest('http://localhos....', 'moodle_group_ge...', Array)
#6 {main}


And here is the short xml document returned when I just enter the following url:

http://localhost/gnulms/webservice/soap/simpleserver.php?wsusername=admin&wspassword=xxx&wsdl=1'

<?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
- <SOAP-ENV:Body>
- <SOAP-ENV:Fault>
<faultcode>MOODLE:error</faultcode>
<faultstring>Access control exception</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I'm using the WAMP environment with PHP 5.3.1. Have you run across this situation before? Any help would be most appreciated.

Thanks,

 
Average of ratings: -
Ken's pic
Re: having trouble with web services in Moodle 2.0
 
Hi,

Looks like I missed a step in enabling the webservices: Site Administration->Users->Authentication->Manage Authentication, then enable Web services authentication. I must have overlooked this step in the documentation, although it doesn't appear in the section on how to enable web services in Moodle...

For some reason the Built-in services are not showing up on the External services page. I defined a custom service and am able to successfully test the built-in functions however.

Ken

 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Hi Ken,
you were right. There were a bug in the token authentication method that required the "Web service Authentication" plugin to be enabled. I've fixed it. All the steps explained in Administration > plugins > Web service > Overview should be right now.

 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Hi,

The path "Site Administration->Users->Authentication->Manage Authentication" doesn't exist in Moodle 2.0 Preview 4.

I found the setting here:

Site administration > Plugins -> Authentication -> Manage Authentication


Still, I am getting the same errors when testing the WS with both simple/token.


 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Hi Anders,
the admin tree has changed recently with the new enrolment system. Can you tell me where you read this text: "Site Administration->Users->Authentication->Manage Authentication". I will update it.

About your original problem:
Your web service params seem okay, can you make your web service user an administrator to see if it's related to permission?
Also if you can update your code to the current CVS version (few web service bugs were fixed since PR4), I'll be curious to know if the problem is still there. If yes, can you write an issue on the tracker (http://tracker.moodle.org).

Thanks for your help, this error message is not helpful, and I try to get rid of these kind of messages.
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Hi Jerome,

I read the text "Site Administration->Users->Authentication->Manage Authentication" in the post by Ken DeVellis - Sunday, 31 January 2010, 10:20 PM of this thread. Must have been a mistake.

Anyway, I found the setting an enabled it.

Then, under Site administration > Users > Permissions > Site administrators, I added the web services user to be a site administrator.

When I test the WS I get the same errors (SoapFault exception: [Receiver] Unknown error in ...) when using simple/token.

Will try to get the current CVS version. We're using SVN here, so I'll see how I go.

When will the latest build be up for download?

Thanks!
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
I've just gone to the Moodle download page, apparently the PR4 is built every day, the last one being two hours ago. So you can download it now.
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
I have checked out the latest Moodle release using git, installed, and started over.

Here is what I did:

<!-- WS Setup Begin -->

Enable WS

Site admin > Advanced Features
TICK: Enable web services
"Save changes"

Enable protocol (SOAP) and WS documentation

Site admin > Plugins > Web services > Manage protocols
Enable SOAP protocol
TICK: Web services documentation
"Save changes"

Create a role for WS

Site admin > Users > Permissions > Define roles > Add new role
Role name: moodle_ws_role
Role archetype: None
Context type: System
Capabilities:
Use SOAP protocol (webservice/soap:use),
moodle/role:assign,
moodle/user:update,
moodle/course:managegroups,
moodle/user:viewdetails,
moodle/user:create,
moodle/site:viewparticipants,
moodle/course:viewparticipants,
moodle/role:review,
moodle/site:accessallgroups,
moodle/course:enrolreview,
moodle/user:delete
"Create this role" --> got an "Error output" here, but role is created!!

Create a user for WS

Site admin > Users > Accounts > Add a new user
Name: Web Services User
Username: moodle_ws
Password: P@$$W0rd
Authentication method: Web services authentication
"Update profile"

Added user to role

Site admin > Users > Permissions > Assign system roles

Enable WS authentication

Site admin > Plugins > Authentication > Manage authentication
Enable Web services authentication
"Save changes"

Create a service and functions

Site admin > Plugins > Web services > External services > Add
Service name: external_ws
TICK: Enabled
TICK: Authorised users only
"Add service"
> Add functions
Select << ALL >> functions
"Add functions"

Create a token

Site admin > Plugins > Web services > Manage tokens
User: Web Services User
Service: external_ws
"Save changes"
Token: f230d145113d7d9b0bb49f3e00072706

<!-- WS Setup End -->

When I test any WS function with simple/token, I now get the error (function name is the function used):

SoapFault exception: [Sender] Function ("moodle_user_get_users_by_id") is not a valid method for this service in /home/user/public_html/ltu_moodle_git/lib/zend/Zend/Soap/Client.php:1113
Stack trace:
#0 /home/
user/public_html/ltu_moodle_git/lib/zend/Zend/Soap/Client.php(1113): SoapClient->__soapCall('moodle_user_get...', Array, NULL, NULL, Array)
#1 /home/
user/public_html/ltu_moodle_git/webservice/soap/locallib.php(152): Zend_Soap_Client->__call('moodle_user_get...', Array)
#2 /home/
user/public_html/ltu_moodle_git/admin/webservice/testclient.php(155): webservice_soap_test_client->simpletest('http://<URL>...', 'moodle_user_get...', Array)
#3 {main}


I have verified that the WS user has the role with the correct capabilities assiged and that the external WS has all functions assigned.

Any ideas?
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
One more step that I had forgotten:

Authorise WS user to use the external WS

Site admin > Plugins > Web Services > External service users
Add WS user to authorised users

--> Got this message: Missing capabilities: moodle/role:assign,moodle/user:update,moodle/course:managegroups,moodle/user:viewdetails,moodle/user:create,moodle/site:viewparticipants,moodle/course:viewparticipants,moodle/role:review,moodle/site:accessallgroups,moodle/course:enrolreview,moodle/user:delete.

... although the role moodle_ws_role has all these capabilities assigned and the WS system user has been assigned this role.

Also, when I go to "Site admin > Plugins > Web Services > External services" and click on "Authorised users" for my WS, it gives this message on the bottom of the page:

Change settings for the authorised users

Web Services User, bla@bla.com
Missing capabilities: moodle/role:assign,moodle/user:update,moodle/course:managegroups,moodle/user:viewdetails,moodle/user:create,moodle/site:viewparticipants,moodle/course:viewparticipants,moodle/role:review,moodle/site:accessallgroups,moodle/course:enrolreview,moodle/user:delete. Missing capabilities.

 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Thanks for the missing capabilities information bug. I'll commit a fix, there is a typo into the SQL request.

I confirm that something going wrong with the SOAP/XML-RPC servers. I'm having a look.

I didn't have any error when I created a role, if you can reproduce please file a issue on the tracker.

Note: use the XML-RPC/REST servers to debug, SOAP is the worst to return error messages.
Note2: web service authentication plugin is mainly use for the username/login web service authentication (called simple). It has also the property to refuse login from the UI.

 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
I pulled the latest release of Moodle 2.0 Preview 4+ from git (CVS) and upgraded.

I then generated a new token and tested again.

This time it worked, and the capabilities bug is gone.

However, when I go to "Manage tokens", I get this error on the top of the page:

Notice: Undefined index: 3 in /home/user/public_html/ltu_moodle_git/lib/adminlib.php on line 6985

Warning: implode() [function.implode]: Invalid arguments passed in /home/user/public_html/ltu_moodle_git/lib/adminlib.php on line 6985
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Hi Anders,
I fixed them too.
Thanks for the report.
 
Average of ratings: -
Picture of udhayakumar R
Re: having trouble with web services in Moodle 2.0
 

can you please tel me

how to create a moodle service which should only retrive the current user id, profile information, with an example code... . .

 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Hi,

the webservice/externallib.php:get_site_info() does something similar (Moodle 2.2).
To create a web service function read: http://docs.moodle.org/dev/Creating_a_web_service_and_a_web_service_function

Cheers,

Jerome

 
Average of ratings: -
Picture of elahe sheikhzadeh
Re: How to get userid via a username ?(web services)
 

How to get userid via a username ?(web services)

 
Average of ratings: -
Picture of Bill Antonia
Re: How to get userid via a username ?(web services)
 
Use core_user_get_users_by_field. Not sure which Moodle version this was supported from though, it's certainly in 2.6
 
Average of ratings: -
Picture of Tim Simon
Re: having trouble with web services in Moodle 2.0
 

Hi,

I have an installation of Moodle 2.0 (updated from 1.9). I am trying to make use of the Web Services, and have followed all of the steps to activate the services. However, when I go to Site Administration > Plugins > Web Services > External Services, and try to add functions, my function list is only 16 services long. From the instructions and common sense, there should be several more services here.

I have one course service, two file services, 7 group services, 2 role services, and 4 user services if that helps diagnosing my mistake any. I have only activated the SOAP protocol. Can anyone think of any reason why I would have a limited number of services available? I've tried activating the rest of the services, not expecting it to make a difference (and it didn't). I am beginning to think that I may have some error in my installation.

Thank you very much; all responses are greatly appreciated.

 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Hi Tim, it seems normal,  there is only few web service functions available. From the last news I had yesterday, someone is going to work on adding some new ones, so there will be more to come smile

In the same time as indicated in the web service FAQ, you can create tracker issues for the functions you think mandatory, vote, or propose patches.

cheers,
Jerome

 
Average of ratings: -
Picture of Nagendra Shukla
Re: having trouble with web services in Moodle 2.0
 

Hi Guys,

I have still not been able to get my hands on to valid wsdl, can anyone post it here.

Nagendra

 
Average of ratings: -
Picture of tushar bhatia
Re: having trouble with web services in Moodle 2.0
 

Hello I trying to Create User using moodl_user_create_user fumction in web services but it giving error

faultCode28194976faultStringCalling parameters do not match signature | ERRORCODE:

 

attaching an xml File

<?xml version="1.0"?>
<methodCall>
<methodName>moodle_user_create_users</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>username</name>
<value>
<string>abebd089-5555-e311-gh56-00155d01105e</string>
</value>
</member>
<member>
<name>password</name>
<value>
<string>Admine51*</string>
</value>
</member>
<member>
<name>firstname</name>
<value>
<string>Test 1</string>
</value>
</member>
<member>
<name>lastname</name>
<value>
<string>Test 1</string>
</value>
</member>
<member>
<name>email</name>
<value>
<string>testing@mail.com</string>
</value>
</member>
<member>
<name>country</name>
<value>
<string>NZ</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>

 
Average of ratings: -
Picture of Jamie Pratt
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writers
Have got past my initial problems and seem to have got my Flex based service browser working. See here : http://tracker.moodle.org/browse/MDL-20808
 
Average of ratings: -
Picture of Rob Barnett
Re: having trouble with web services in Moodle 2.0
 
Hoping someone could assist me. I set up Moodle 2.0 on a redhat server with php 5.3.1 with soap enabled. I receive the following error when I test the web service client using the SOAP protocol. It works fine with REST but I really need SOAP.

SoapFault exception: [Receiver] Unknown error in /var/www/html/moodle2/lib/zend/Zend/Soap/Client.php:1063
Stack trace:
#0 /var/www/html/moodle2/lib/zend/Zend/Soap/Client.php(1063): SoapClient->__soapCall('moodle_user_cre...', Array, NULL, NULL, Array)
#1 /var/www/html/moodle2/webservice/soap/locallib.php(152): Zend_Soap_Client->__call('moodle_user_cre...', Array)
#2 /var/www/html/moodle2/admin/webservice/testclient.php(151): webservice_soap_test_client->simpletest('http://moodlete...', 'moodle_user_cre...', Array)
#3 {main}


I've checked and I have Web Services enabled and SOAP protocol is active. Do I need anything else installed on the server besides enabling soap when I configured PHP or am I going down the wrong path? Thanks for your help.
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Hi,

I have exactly the same problem.

Would anybody know if this is a Moodle 2.0 problem?

I am currently running version "Preview 4"

Thanks
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
Hi,
can you give me the full error message from your log?

Few notes:
1. test client error messages are not entirely displayed (MDL-23519)
2. All web services functions are now declared with their required capabilities in /lib/db/services.php. When an administrator adds a function to a service, the required capabilities are now displayed. Moodle also display missing user capabilities when the administrator creates a token. It is a recent improvement.
3. currently SOAP supports PHP client only (Not tested with Java/.Net, it most likely going to fail as the generated WSDL will not be detailed enough)

Thanks,
Jerome
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Hi Jerome,

Thanks for your reply.

The web service that I am testing is "moodle_user_create_users" and I am testing it via the Moodle Site Administration (test client).

This is what is displayed on the page after I test the WS:

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

URL: http://<URL>/ltu_moodle/webservice/soap/server.php?wstoken=10951dc9b2db0875502ea2b693529af5
SoapFault exception: [Receiver] Unknown error in /home/user/public_html/ltu_moodle/lib/zend/Zend/Soap/Client.php:1113
Stack trace:
#0 /home/user/public_html/ltu_moodle/lib/zend/Zend/Soap/Client.php(1113): SoapClient->__soapCall('moodle_user_cre...', Array, NULL, NULL, Array)
#1 /home/user/public_html/ltu_moodle/webservice/soap/locallib.php(152): Zend_Soap_Client->__call('moodle_user_cre...', Array)
#2 /home/user/public_html/ltu_moodle/admin/webservice/testclient.php(155): webservice_soap_test_client->simpletest('http://<URL>...', 'moodle_user_cre...', Array)
#3 {main}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

I will also post the apache logs once I get hold of them.

Thanks for your help!

Anders
 
Average of ratings: -
Picture of Jérôme Mouneyrac
Re: having trouble with web services in Moodle 2.0
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
I just run moodle_user_create_users unit tests, they passed.
Could you let me know your parameters?
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Here are my parameters:

Authentication method: token
Protocol: SOAP protocol
Function: moodle_user_create_users

Token: 10951dc9b2db0875502ea2b693529af5
Username: new_user
Password: password123
Firstname: Scott
Lastname: Tiger
Email: scott.tiger@example.com
Customfieldtype: <BLANK>
Customfieldvalue: <BLANK>

--> Execute

SoapFault exception: [Receiver] Unknown error in /home/user/public_html/ltu_moodle/lib/zend/Zend/Soap/Client.php:1113
 
Average of ratings: -
Picture of Anders Landberg
Re: having trouble with web services in Moodle 2.0
 
Further, when I capture the parameters in the exception, I get the following:

params: Array ( [users] => Array ( [0] => Array ( [username] => new_user [password] => password123 [firstname] => Scott [lastname] => Tiger [email] => scott.tiger@example.com [auth] => manual [idnumber] => [emailstop] => 0 [lang] => en ) ) ) )

All looks OK.
 
Average of ratings: -
Picture of Esteban Chamba Jimenez
Re: having trouble with web services in Moodle 2.0
 

I'd like know if someone resolved this problem, I'm getting the same error

 
Average of ratings: -
Picture of tushar bhatia
Re: having trouble with web services in Moodle 2.0
 

I am Trying to create USER using moodle_user_create_user webservices

but it giving error

faultCode28194976faultStringCalling parameters do not match signature | ERRORCODE:

Please Help

Attaching XML

<?xml version="1.0"?>
<methodCall>
<methodName>moodle_user_create_users</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>username</name>
<value>
<string>abebd089-5555-e311-gh56-00155d01105e</string>
</value>
</member>
<member>
<name>password</name>
<value>
<string>Admine51*</string>
</value>
</member>
<member>
<name>firstname</name>
<value>
<string>Test 1</string>
</value>
</member>
<member>
<name>lastname</name>
<value>
<string>Test 1</string>
</value>
</member>
<member>
<name>email</name>
<value>
<string>testing@mail.com</string>
</value>
</member>
<member>
<name>country</name>
<value>
<string>NZ</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>

 

Please Help

Thanks In Advance

 
Average of ratings: -
Picture of asha chaparala
Re: having trouble with web services in Moodle 2.0
 
Hi sir,
I am unable to find how to get user role through webservises.How can i user role for that site through webservises.please tell me how to fix the issue?

 
Average of ratings: -