Webservice to create new user account

Webservice to create new user account

by Moodle User -
Number of replies: 29

Hello,

I need to create a webservice which will accept student details (first and last name, address, username etc) and creates a user account in Moodle.

Please let me know how can i acheive this. Any help would be greatly appreciated.

Average of ratings: -
In reply to Moodle User

Re: Webservice to create new user account

by Josh Marshall -
I've been looking for the same sort of explanation for weeks now. There seems to be a lot of people that have questions regarding phases beyond the basic setup, so obviously it works. I just can't find a tutorial that covers all the bases.
In reply to Josh Marshall

Re: Webservice to create new user account

by Moodle User -
I just found following thread in Webservice forum. But need to go through the post.
In reply to Josh Marshall

Re: Webservice to create new user account

by Antonio Duran -
Hi. Are you talking about Moodle 1.9 or Moodle 2.0. About 2.0 I don't know anything.

As for 1.9. I have developed a Joomla-Moodle integration project that uses web services.
In Moodle side, it is a new auth plugin that creates some new web-services to be accessed via direct XML-RPC (no mnet encryption) from Joomla. One of those services creates a new user.
Details are specific to my project, but maybe looking at the code can help you get started.

I looked for the docs I used when I started, but some of them are being replaced with Moodle 2.0 documentation.

The project can be found at:
http://joomdle.com

Regards,
Antonio
In reply to Antonio Duran

Re: Webservice to create new user account

by Patrick Pollet -
Hello,

Create user in one of the 110 operations allowed by OK Tech WebService available on Moodle contrib's CVS http://cvs.moodle.org/contrib/patches/ws/wspp/ and here http://cipcnet.insa-lyon.fr/Members/ppollet/public/moodlews/. This works against Moodle prior to 2.0


Installation and usage is documented in the file INSTALL . In there you will find usage of the provided wsdl2php utility to create 'php skeletons' for all supported operations in a folder tests/ (see also http://cipcnet.insa-lyon.fr/Members/ppollet/public/moodlews/wsdl2php/)

Among these the script tests/test_add_user.php

<?php
require_once ('../MoodleWS.php');

$moodle=new MoodleWS();
require_once ('../auth.php');
/**test code for MoodleWS: add on course
* @param integer $client
* @param string $sesskey
* @param userDatum $user
* @return editUsersOutput
*/

$lr=$moodle->login(LOGIN,PASSWORD);
$user= new userDatum();
$user->setAction('');
$user->setId(0);
$user->setConfirmed(0);
$user->setPolicyagreed(0);
$user->setDeleted(0);
$user->setUsername('');
$user->setAuth('');
$user->setPassword('');
$user->setPasswordmd5('');
$user->setIdnumber('');
$user->setFirstname('');
$user->setLastname('');
$user->setEmail('');
$user->setEmailstop(0);
$user->setIcq('');
$user->setSkype('');
$user->setYahoo('');
$user->setAim('');
$user->setMsn('');
$user->setPhone1('');
$user->setPhone2('');
$user->setInstitution('');
$user->setDepartment('');
$user->setAddress('');
$user->setCity('');
$user->setCountry('');
$user->setLang('');
$user->setTimezone(0);
$user->setLastip('');
$user->setTheme('');
$user->setDescription('');
$user->setMnethostid(0);
$res=$moodle->add_user($lr->getClient(),$lr->getSessionKey(),$user);
print_r($res);
print($res->getUsers());

$moodle->logout($lr->getClient(),$lr->getSessionKey());

?>

So just fill the blanks (or comment out data that you do not want to send to Moodle) and enjoy...


this answer is already in OKTech Ws Moodle's forum :

http://moodle.org/mod/forum/post.php?reply=615268


Similary you will find test_update_user that expect also an userDatum object filled with the requested changes and a string giving which of the field of the Userdatum record is to be used to locate the target user (likely id, idnumber, username or email that are unique in Moodle DB).


Finally you will find test_delete_user that expect just a unique value and an identifying string such as

// delete by username
$res=$moodle->delete_user($lr->getClient(),$lr->getSessionKey(),'me','username');

or

$res=$moodle->delete_user($lr->getClient(),$lr->getSessionKey(),'me@somewhere','email');


Alternatively you may the edit_users operation for bulk processing . It expect an array of userDatum records (each one built as above with more of less details depending of the wanted operation) plus for each an operation attribute named action (add, udpate or delete). Internally the add_user operation build the array expected by edit_users and calls it. See source code in mdl_soap_server.class.php


The same goes for other entities (courses, groups, groupings, categories, section, labels, wiki, forums ...)

And if you do not want to use php, sample codes are provided in java or Python on the project 's page with usage of wsdl2java or wsdl2py to create almost the same skeletons in these languages.

Or install the graphical SoapUI utility that will create for you skeleton of requests based on the sent wsdl. These skeletons will help you to test the service and guess the required parameters to be used in you favorite language.

Cheers.




In reply to Patrick Pollet

Re: Webservice to create new user account

by Pinal Bhatt -
Yes i am also looking for some proper documentation for using web services form moodle. Initially i was told that this feature will be available in moodle 2.0 but reading posts in this forum i can see that web services are also available in prior versions.

I am new to PHP and Moodle. Basically I am a .net guy and looking for integrating moolde with our existing ASP.Net application & Facebook connect.

I have Moodle 1.9.7 (Build: 20091126) running.


I tried to go thru different documentation but not getting on proper track. If any body can guide me or provide pointers for systematic setup of web service and their usage form ASP.Net application.

Thanks in advance.

- Pinal Bhatt
In reply to Pinal Bhatt

Re: Webservice to create new user account

by Moodle User -

Hello Patrick,

Thanks for your reply and detailed guidance. I will start working on this and will keep you posted regarding the status.

Hi Pinal,

I am in exactly same situation as you are ...am a .Net guy but need to create a webservice in PHP for Moodle version 1.9.7

I am going to follow the guidance that Patrick has mentioned in my post and will let you guys know how is it going.

Thanks.

In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Hey Patrick,

I was working on the steps mentioned in INSTALL file but not sure how to and where to execute the following command:

on the server go to wspp/clients and run the following 

php ../wsdl2php.php http://yourmoodle/wspp/wsdl_pp.php

I am very new to PHP and so nay advice would be a great help.

Thanks a lot.

In reply to Moodle User

Re: Webservice to create new user account

by Patrick Pollet -
Well, this command has to be launched in a console (nix) or a Dos command shell (Windows)

something like

cd /var/www/html/moodle/wspp/clients
or
cd d:\inetd\ .....\moodle\wspp\clients. (don't know nothing under Windows)

and then the magic command above


AS far as SoapUi is concerned you have a demo video on their site http://www.soapui.org/

and also (even if you do not understand French, you can follow my mouse gestures wink) on my site
http://cipcnet.insa-lyon.fr/moodle/file.php/1/soapui_demo.flv for an example of use against a real Moodle server !

Cheers


In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Thanks a lot Patrick for the reply.

Sorry that I did not mentioned in my previous post that my Moodle site is hosted on remote server. However I am having access to that remote server through cPanel.

Can you please tell me how can I execute the above commands using cPanel?

For using SOAPUi i will review the videos on their site as well as one avaiable on your site.

Regards.

In reply to Moodle User

Re: Webservice to create new user account

by Patrick Pollet -
I am afraid that cPanel does not give you command line access to the remote server so

1) on you local machine, in some directory get only the files wspp/wsdl2php.php and wspp/clients/auth.php.dist

2) make sure php on that local machine has phpsoap extension installed

3) rename auth.php.dist to auth.php and edit it to provide an account that has access to Moodle (either admin accont ot an account using the webservice authentification méthod).

4) you should get something like

ppollet@prope:/tmp/test$ ll
total 28
-rw-r--r-- 1 ppollet ppollet 156 2010-03-01 17:36 auth.php
-rw-r--r-- 1 ppollet ppollet 24382 2010-03-01 17:36 wsdl2php.php


5)run the command

ppollet@prope:/tmp/test$ php wsdl2php.php http://yourmoodle/wspp/wsdl_pp.php

you should get

Writing affectRecord.php...ok
Writing userRecord.php...ok
Writing groupRecord.php...ok
Writing groupingRecord.php...ok
Writing sectionRecord.php...ok
Writing courseRecord.php...ok
Writing gradeRecord.php...ok
Writing enrolRecord.php...ok
Writing eventRecord.php...ok
Writing changeRecord.php...ok
Writing roleRecord.php...ok
Writing categoryRecord.php...ok
Writing resourceRecord.php...ok
Writing activityRecord.php...ok
Writing fileRecord.php...ok
Writing assignmentSubmissionRecord.php...ok
Writing labelRecord.php...ok
Writing forumRecord.php...ok
Writing assignmentRecord.php...ok
Writing databaseRecord.php...ok
Writing wikiRecord.php...ok
Writing pageWikiRecord.php...ok
Writing userDatum.php...ok
Writing courseDatum.php...ok
Writing labelDatum.php...ok
Writing groupDatum.php...ok
Writing groupingDatum.php...ok
Writing categoryDatum.php...ok
Writing sectionDatum.php...ok
Writing forumDatum.php...ok
Writing assignmentDatum.php...ok
Writing databaseDatum.php...ok
Writing wikiDatum.php...ok
Writing pageWikiDatum.php...ok
Writing loginReturn.php...ok
Writing editUsersInput.php...ok
Writing editUsersOutput.php...ok
Writing getUsersReturn.php...ok
Writing editCoursesInput.php...ok
Writing editCoursesOutput.php...ok
Writing getCoursesReturn.php...ok
Writing getGradesReturn.php...ok
Writing enrolStudentsReturn.php...ok
Writing getRolesReturn.php...ok
Writing getGroupsReturn.php...ok
Writing getEventsReturn.php...ok
Writing getLastChangesReturn.php...ok
Writing getCategoriesReturn.php...ok
Writing getResourcesReturn.php...ok
Writing getSectionsReturn.php...ok
Writing getActivitiesReturn.php...ok
Writing getAssignmentSubmissionsReturn.php...ok
Writing editLabelsInput.php...ok
Writing editLabelsOutput.php...ok
Writing editGroupsInput.php...ok
Writing editGroupsOutput.php...ok
Writing editGroupingsInput.php...ok
Writing editGroupingsOutput.php...ok
Writing editCategoriesInput.php...ok
Writing editCategoriesOutput.php...ok
Writing editSectionsInput.php...ok
Writing editSectionsOutput.php...ok
Writing editForumsInput.php...ok
Writing editForumsOutput.php...ok
Writing editAssignmentsInput.php...ok
Writing editAssignmentsOutput.php...ok
Writing editDatabasesInput.php...ok
Writing editDatabasesOutput.php...ok
Writing editWikisInput.php...ok
Writing editWikisOutput.php...ok
Writing editPagesWikiInput.php...ok
Writing editPagesWikiOutput.php...ok
Writing getAllForumsReturn.php...ok
Writing getAllLabelsReturn.php...ok
Writing getAllWikisReturn.php...ok
Writing getAllPagesWikiReturn.php...ok
Writing getAllAssignmentsReturn.php...ok
Writing getAllDatabasesReturn.php...ok
Writing getAllGroupingsReturn.php...ok
Writing tests/test_login.php...ok
Writing tests/test_logout.php...ok
Writing tests/test_edit_users.php...ok
Writing tests/test_get_users.php...ok
Writing tests/test_edit_courses.php...ok
Writing tests/test_get_courses.php...ok
Writing tests/test_get_resources.php...ok
Writing tests/test_get_version.php...ok
Writing tests/test_get_sections.php...ok
Writing tests/test_get_instances_bytype.php...ok
Writing tests/test_get_grades.php...ok
Writing tests/test_get_user_grades.php...ok
Writing tests/test_get_course_grades.php...ok
Writing tests/test_enrol_students.php...ok
Writing tests/test_unenrol_students.php...ok
Writing tests/test_get_last_changes.php...ok
Writing tests/test_get_events.php...ok
Writing tests/test_get_course.php...ok
Writing tests/test_get_course_byid.php...ok
Writing tests/test_get_course_byidnumber.php...ok
Writing tests/test_get_user.php...ok
Writing tests/test_get_roles.php...ok
Writing tests/test_get_role_byid.php...ok
Writing tests/test_get_role_byname.php...ok
Writing tests/test_get_categories.php...ok
Writing tests/test_get_category_byid.php...ok
Writing tests/test_get_category_byname.php...ok
Writing tests/test_get_my_courses.php...ok
Writing tests/test_get_my_courses_byusername.php...ok
Writing tests/test_get_my_courses_byidnumber.php...ok
Writing tests/test_get_user_byusername.php...ok
Writing tests/test_get_user_byidnumber.php...ok
Writing tests/test_get_user_byid.php...ok
Writing tests/test_get_users_bycourse.php...ok
Writing tests/test_count_users_bycourse.php...ok
Writing tests/test_get_courses_bycategory.php...ok
Writing tests/test_get_groups_bycourse.php...ok
Writing tests/test_get_group_byid.php...ok
Writing tests/test_get_groups_byname.php...ok
Writing tests/test_get_group_members.php...ok
Writing tests/test_get_grouping_members.php...ok
Writing tests/test_get_my_id.php...ok
Writing tests/test_get_my_group.php...ok
Writing tests/test_get_my_groups.php...ok
Writing tests/test_get_teachers.php...ok
Writing tests/test_get_students.php...ok
Writing tests/test_has_role_incourse.php...ok
Writing tests/test_get_primaryrole_incourse.php...ok
Writing tests/test_get_activities.php...ok
Writing tests/test_count_activities.php...ok
Writing tests/test_get_assignment_submissions.php...ok
Writing tests/test_add_user.php...ok
Writing tests/test_add_course.php...ok
Writing tests/test_add_group.php...ok
Writing tests/test_add_grouping.php...ok
Writing tests/test_add_section.php...ok
Writing tests/test_add_label.php...ok
Writing tests/test_add_forum.php...ok
Writing tests/test_add_database.php...ok
Writing tests/test_add_assignment.php...ok
Writing tests/test_add_wiki.php...ok
Writing tests/test_add_pagewiki.php...ok
Writing tests/test_delete_user.php...ok
Writing tests/test_add_category.php...ok
Writing tests/test_delete_course.php...ok
Writing tests/test_delete_group.php...ok
Writing tests/test_delete_grouping.php...ok
Writing tests/test_update_user.php...ok
Writing tests/test_update_course.php...ok
Writing tests/test_update_section.php...ok
Writing tests/test_update_group.php...ok
Writing tests/test_update_grouping.php...ok
Writing tests/test_edit_labels.php...ok
Writing tests/test_edit_groups.php...ok
Writing tests/test_edit_assignments.php...ok
Writing tests/test_edit_databases.php...ok
Writing tests/test_edit_categories.php...ok
Writing tests/test_edit_sections.php...ok
Writing tests/test_edit_forums.php...ok
Writing tests/test_edit_wikis.php...ok
Writing tests/test_edit_pagesWiki.php...ok
Writing tests/test_affect_course_to_category.php...ok
Writing tests/test_affect_label_to_section.php...ok
Writing tests/test_affect_forum_to_section.php...ok
Writing tests/test_affect_section_to_course.php...ok
Writing tests/test_affect_user_to_group.php...ok
Writing tests/test_affect_group_to_course.php...ok
Writing tests/test_affect_wiki_to_section.php...ok
Writing tests/test_affect_database_to_section.php...ok
Writing tests/test_affect_assignment_to_section.php...ok
Writing tests/test_affect_user_to_course.php...ok
Writing tests/test_affect_pageWiki_to_wiki.php...ok
Writing tests/test_remove_user_from_course.php...ok
Writing tests/test_get_all_groups.php...ok
Writing tests/test_get_all_forums.php...ok
Writing tests/test_get_all_labels.php...ok
Writing tests/test_get_all_wikis.php...ok
Writing tests/test_get_all_pagesWiki.php...ok
Writing tests/test_get_all_assignments.php...ok
Writing tests/test_get_all_databases.php...ok
Writing tests/test_get_all_groupings.php...ok
Writing tests/test_remove_user_from_group.php...ok
Writing tests/test_edit_groupings.php...ok
Writing tests/test_remove_group_from_grouping.php...ok
Writing tests/test_affect_group_to_grouping.php...ok
Writing MoodleWS.php...ok
Writing test_MoodleWS.php...ok
Generated 105 functions calls and 79 custom datatypes



6) go into the created tests directory and start playing around

ppollet@prope:/tmp/test$ cd tests/
ppollet@prope:/tmp/test/tests$ php test_get_r
test_get_resources.php test_get_role_byid.php test_get_role_byname.php test_get_roles.php
ppollet@prope:/tmp/test/tests$ php test_get_roles.php


getRolesReturn Object
(
[roles] => Array
(
...
[6] => stdClass Object
(
[error] =>
[id] => 7
[name] => Utilisateur authentifié
[shortname] => user
[description] => Tous les utilisateurs connectés.
[sortorder] => 6
)

)

)



In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

I think i need to first install PHP on my machine(Windows Xp) to enable soap extension, right?

Thanks so much Patrick for helping me on this project. I sincerely appeaciate your time and guidance in this regard. smile

In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Hello Patrick,

As suggested by you, I installed PHP on my local machine(with Windows Xp):

1) created a directory "phpfiles" with files wspp/wsdl2php.php and wspp/clients/auth.php.dist

2) phpsoap extension installed on my local machine

3) rename auth.php.dist to auth.php and edit it to provide an account that has access to Moodle (either admin accont ot an account using the webservice authentification méthod).

But i am not sure how to do step 4 as mentioned by you:

ppollet@prope:/tmp/test$ ll
total 28
-rw-r--r-- 1 ppollet ppollet 156 2010-03-01 17:36 auth.php
-rw-r--r-- 1 ppollet ppollet 24382 2010-03-01 17:36 wsdl2php.php


All I am doing is going to the directory "phpfiles"(where I copied the two files) through the command prompt and then executing the php wsdl2pp.php command.

But I am getting error screen saying "CLI encountered a problem and needs to colse"

kindly advise.

In reply to Moodle User

Re: Webservice to create new user account

by Pinal Bhatt -
Hi moodleuser,

that are all linux commands. We need to do this on dos command console.

I copied the two files in D:\mt folder and renamed file accordingly. so my command will be like this:

D:\mt>php wsdl2php.php http://www.moodle1.com/moodle/wspp/wsdl_pp.php


In reply to Pinal Bhatt

Re: Webservice to create new user account

by Moodle User -

Hi Pinal,

Yes I tried executing the php command using command prompt in windows after copying these two files to c:\phpfiles directory(the temporary directory i created for these 2 files.), but getting error screen "CLI has encountered a problem and needs to close".

Just to mention that my Moodle and database is hosted on Remote server and I am executing this command on my local machine. Is this correct way?

Please advice. Thankyou so much.

In reply to Moodle User

Re: Webservice to create new user account

by Pinal Bhatt -
no idea for this error buddy, but that worked for me without error.
In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Also not sure about how to test the web service login operation as mentioned install file:

6) test the Web Service login operation. The easiest way is surely using SoapUI graphical  interface.
    - create a new Wsdl project with URL
http://yourmoodle/wspp/wsdl_pp.php .
    - test login operation, and if successfull, copy the returned client number and sessionkey in the corresponding input fields of other operation

It would be really helpful if someone can explain me about how to execute the above step and how to use SOAPUI graphical interface.

Thanks so much.

In reply to Moodle User

Re: Webservice to create new user account

by Pinal Bhatt -
Eureka eureka eureka.... i got moodle service running and successfully called from .net client.

Here are the simple steps i did. and you can see the video of accessing moodle service from .net client at
http://www.screencast.com/users/PinalBhatt/folders/Default/media/b93eb27f-eca3-4a94-861d-5c9911b54abe


Steps:
  1. make sure the phpsoap extension (for php5 !) in installed
  2. unzip the wspp_xxx.zip into your main Moodle installation folder (i used wspp_1.6.2 version)
  3. copy wspp/lang/en_utf8/wspp.php
    into your moodledata/lang/en_utf8_local folder .
  4. edit moodle/admin/settings/misc.php and add the line

    require("$CFG->dirroot/wspp/admin/wspp.php");

    just before this line
    // hidden scripts linked from elsewhere

  5. Go to your moodle site as administrator and go to "Notifications" under "site Administration" links and complete the upgrade process. (i kept default settings)
  6. Verification step: Make sure the WSDL file (that describes the offered services ) is accessible by calling in a browser 'http://yourmoodle/wspp/wsdl_pp.php ' . It should present you a file (moodlews.wsdl) to download. You may cancel the operation since this file is not needed. It that fails, then it means there are some issues.

  7. Thats it...thats all we need to do on moodle side... rest is on .net side.
  8. In Visual Studio .Net project, add web reference to http://yourmoodle/wspp/wsdl_pp.php. (important: when you enter this link and click go it will ask to open/save the file. please select "open" ) You can see video at above links.
  9. And rest is accessing webservices as usual we do in .net. below is the sample code to get list of categories:

    Moodle.MoodleWS s = new Moodle.MoodleWS();
    Moodle.loginReturn lr = s.login("testuser", "testuser");

    Moodle.getCategoriesReturn res = s.get_categories(lr.client, lr.sessionkey);
    Response.Write(res.categories[0].name);
    s.logout(lr.client, lr.sessionkey);

so steps are really simple, we were just getting confused by complected steps.

Thanks & Regards,
Pinal Bhatt
http://www.P-Bhatt.com
http://lms.Learning-Leisure.com

Average of ratings: Useful (3)
In reply to Pinal Bhatt

Re: Webservice to create new user account

by Patrick Pollet -
Hi Pinal,

Glad you did it wink Thanks for the screncast under Visual Studio.

I shall reuse you step 5 and 6 that are 'clearer' and in better english in my INSTALL file.

Cheers.

Hi Moodle user,

You have definitively an error with your php installation on your Windows, but as Pinal demontrated, you may just not need php to test the Web Service on your local machine. I gave that solution since I am not at all a Windows guy and know nothing about .net and Visual Studio.

In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Hi Pinal,

I sincerely thanks for replying to my post and glad to know that you successfully did it smile.

I have few questions though...

1) how should I pass parameters from .Net file to a function in this web service. i.e. I want to use add_user($lr->getClient(),$lr->getSessionKey(),$user) funtion which requires $user object. How should i populate this object through a .Net file? Do I need to create a similar object in .net and pass that one?

2) How can I call a .net webservice from Moodle, i.e. I need to call a web service when a student receives the completion certificate and passing values such as username, course id, score etc.

Please advice. Best regards.

Hello Patrick,

I thank you for taking time to reply and help me out with this task. I greatly appreciate this.

Best Regards.

In reply to Moodle User

Re: Webservice to create new user account

by Pinal Bhatt -
Hi Moodle User,

You dont need to create any new classes, when you add a web reference Visual Studio generates proxy for the service and it creates necessary classes in .net.

To pass parameters from .net to web service you can see the code i have submitted. below is the code to call create user web service:

Please note that in below code "Moodle" is the namespace name i have given to web service reference.

Moodle.MoodleWS s = new Moodle.MoodleWS();
Moodle.loginReturn lr = s.login("admin", "Ganesh123");

Moodle.userDatum user = new Moodle.userDatum();

user.action="";
user.idnumber = "FB103";
user.confirmed ="1";
user.policyagreed = "1";
user.deleted = "0";
user.username = "testuser04";
user.auth = "manual";
user.password = "";
user.firstname = "test03";
user.lastname = "user03";
user.email = "pinalbhatt2@msn.com";
user.city = "NU";
user.country = "US";
user.timezone = "99";

Moodle.editUsersOutput u = s.add_user(lr.client, lr.sessionkey, user);
s.logout(lr.client, lr.sessionkey);


- Pinal Bhatt


Average of ratings: Useful (1)
In reply to Pinal Bhatt

Re: Webservice to create new user account

by Moodle User -

Hey Pinal,

A big thanks for such a prompt reply. I wil try this and let you know smile

Any clue on how to achieve the 2nd part, calling .Net web service from Moodle?

You were a great help.

Thanks again.

Ritu

In reply to Pinal Bhatt

Re: Webservice to create new user account

by Patrick Pollet -
Sounds good to me wink

actually all 'empty' values are unneeded and are ignored by the web service, so the following lines could be removed:

user.action="";
user.deleted = "0";
user.password = "";

Good show wink

Cheers.
In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Hello Guys,

I have insatlled latest WSPP folder to my Moodle 1.9.7 and I am trying to call add user function froma .net client as mentioned by Pinal.

But I am getting the Content Type in Response Headers as text/html instead of application/soap+xml. I did changed then header in wsdl_pp.php to

header('Content-Type: application/soap+xml; charset=UTF-8');

Also my Site administration block disappeared after I enabled this Web service plug.

Please advice. Thanks so much.

In reply to Moodle User

Re: Webservice to create new user account

by Patrick Pollet -
Hi Moodle user,

I am afraid that you have broken something when editing the file moodle/admin/settings/misc.php

see step 4 on Pinal's message above or the INSTALL file

edit moodle/admin/settings/misc.php and add the line

require("$CFG->dirroot/wspp/admin/wspp.php");

just before this line
// hidden scripts linked from elsewhere


so it explains that the admin block has diseappared (something is broken in file misc.php) and that you get an text/html answer (likely an error message sent by Moodle), rather that the expected XML.
Try to fetch the wsdl file by calling

http://yourmoodle/wspp_wsdl_pp.php ...

you should not change the header sent by wsdl_pp.php...

Cheers

Average of ratings: Useful (1)
In reply to Patrick Pollet

Re: Webservice to create new user account

by Moodle User -

Thanks Patrick this did worked, my Site Admin block is back and I reverted the content type header back to original.

Also when i am browsing my wsdl http://yourmoodle/ws/wspp/wsdl_pp.php it is showing me the correct Moodlewsdl.xml document.

But still I am not able to access the webservice through .Net as mentioned by Pinal.

Pinal, you mentioned in your post that "You dont need to create any new classes, when you add a web reference Visual Studio generates proxy for the service and it creates necessary classes in .net"

This is not happening for me, Visual Studio is not generating the necessary classes and I am getting response header in text/html format as opposed to application/xml. What could be the reason for this.  One more thing to mention that I am having a extra directory "ws" from my root directory i.e ws/wspp/ and so http://mymoodle.com/ws/wspp/wspp_pp.php which is still giving me correct xml file. I have edited the path to the root config.php in wsdl_pp.php file accordingly.

Any advice would be helpful. Thanks!

In reply to Moodle User

Re: Webservice to create new user account

by Patrick Pollet -
> One more thing to mention that I am having a extra directory "ws" from my root directory i.e ws/wspp/...

this IS the reason, please install it into its proper place !




In reply to Pinal Bhatt

Re: Webservice to create new user account

by loic jeannin -
Hi, I've created a python script to use the webservice (moodle 1.9.6) :

--
from suds.client import Client
import pdb
import md5

url = 'http://mymoodle/wspp/wsdl_pp.php'
client = Client(url)

c, sk = client.service.login('admin', 'admin')

u = client.factory.create('userDatum')

u.username = 'user'
u.firstname = 'User'
u.lastname = 'FOOBAR'
u.email = 'user@user.com.br'
u.password = 'user'
u.auth = 'manual'
u.city = 'Brasilia'
u.country = 'BR'
u.confirmed = '1'
u.timezone = '99'
u.idnumber = '234'

print client.service.add_user(c[1], sk[1], u)
--

At first the error message was containing the missing properties, so I added those one by one : missing username, missing password etc ...

But now I've this :
(editUsersOutput){
users[] =
(userRecord){
error = "erreur en créant l'utilisateur 234."

So I'm a bit lost, what am I doing wrong now ?

Thanks,
PS: all the get_* services are working great, so it's not an authentication problem
In reply to loic jeannin

Re: Webservice to create new user account

by loic jeannin -
After a deep debug (that goes into insert_record), it appears that policyagreed and emailstop have to be set.
Moodle 1.9.7 / mysql
In reply to Pinal Bhatt

Re: Webservice to create new user account

by gopi kishore -

hi pinal,

i follow your steps and installed wspp. but i am getting the below error

Fatal error: require_once() [function.require]: Failed opening required '../config.php' (include_path='.;C:\XAMPP\php\PEAR') inC:\XAMPP\htdocs\moodle1\moodle\ws\wspp\wsdl_pp.php on line 24.

please tell me the mistak.

Thnaks