REST-API: Create new users via auth_email_signup_user

REST-API: Create new users via auth_email_signup_user

by housemaster Delome -
Number of replies: 5

Hi,

I want to add new users to our moodle system in a webapp via the REST-API. Since you need to be logged in for "core_user_create_users" to work, I thought "auth_email_signup_user" would be the correct function. But here I always get the "Invalid parameter value detected" error... The API documentation says I need a username, password, firstname, lastname and email parameter, but it won't work:

https://<moodle>/webservice/rest/server.php?wstoken=xyz&wsfunction=auth_email_signup_user&moodlewsrestformat=json&username=test&password=xyz&firstname=house&lastname=master&email=house@xyz.com

The parameter format for core_user_create_users is "users[0][firstname], users[0][lastname]" etc. but this won't work either. 

Any ideas what I am doing wrong?

Average of ratings: -
In reply to housemaster Delome

Re: REST-API: Create new users via auth_email_signup_user

by housemaster Delome -
Ok it's working now. I enabled the developer debug messages and it told me I forgot to pass the parameters of the custom profile files, which were mandatory as well.
If anyone wonders how to pass multiple custom fields:
&customprofilefields[0][type]=string&customprofilefields[0][name]=profile_field_NAME&customprofilefields[0][value]=placeholder&customprofilefields[1][type]=string&customprofilefields[1][name]=profile_field_NAME2&customprofilefields[1][value]=placeholder

...but now I have to confirm the user and don't know the "secret" parameter. Anyone knows how to get that one?
The function I'm using is core_auth_confirm_user, which requires the username and the secret.
In reply to housemaster Delome

Re: REST-API: Create new users via auth_email_signup_user

by Lucas Macedo -
Have you gotten the "secret" parameter? I have not found any documentation on how to get it, I also need to use the core_auth_confirm_user function
In reply to housemaster Delome

Re: REST-API: Create new users via auth_email_signup_user

by Andi Sobandi -

Hi, Kevin Zapp

I'm using auth_email_signup but I can't add custom profile fields

I look and write code like API Documentation but it doesn't work

moodlewsrestformat:json
wstoken:xxxxxxxxxxxxxxxxxxxxxxxx
wsfunction:auth_email_signup_user
username:johndoe
firstname:John
lastname:Doe
password:xxxxxxx
email:johndoe@mail.local
city:London
country:EN
customprofilefields[0][type]:foo
customprofilefields[0][name]:Foo
customprofilefields[0][value]:Sample

I'm using moodle 3.9 and I'm using Postman for testing

I'm getting an error message

{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected (Invalid fieldFoo)","debuginfo":"Invalid fieldFoo"}

Could you please help me, what is the correct way to add custom profile fields in auth_email_signup

Thank You!

In reply to Andi Sobandi

Ri: Re: REST-API: Create new users via auth_email_signup_user

by Alan Quaino -
I'm also stuck in this situation. Everything is correct and I followed the Moodle API documentation. Also using Postman, and I'm getting the same error.
Any help or solution?

Thanks