core_user_create_users and core_user_update_users are missing some core fields

core_user_create_users and core_user_update_users are missing some core fields

by Nicholas Stefanski -
Number of replies: 7

I was looking to start using Moodle's existing webservices to create new users from an external source, but I noticed that the core_user webservices are missing several fields for users, including phone1, institution, department, and maildisplay. Maybe one of the core developers could weigh in here, are there any plans to add these fields in? If there's not a lot of bandwidth among the core developers to do this right now, would you accept pull requests for these additions? smile

Average of ratings: -
In reply to Nicholas Stefanski

Re: core_user_create_users and core_user_update_users are missing some core fields

by biboy atienza -

Nicholas,

Are you also populating a Custom Field/s on creating a new user using core_user_create_users?
I am failing on filling it up. sad

In reply to biboy atienza

Re: core_user_create_users and core_user_update_users are missing some core fields

by Dorel Manolescu -
Picture of Plugin developers

@biboy atienza

Looking in the code there is support for custom fields in the web-service:

###

// Custom fields.
if (!empty($user['customfields'])) {
foreach ($user['customfields'] as $customfield) {
// Profile_save_data() saves profile file it's expecting a user with the correct id,
// and custom field to be named profile_field_"shortname".
$user["profile_field_".$customfield['type']] = $customfield['value'];
}
profile_save_data((object) $user);
}

###

Just check that you have the correct syntax there. Please find attached a screen-shot with a postman request.

Any other questions let us know.

Regards



Attachment custom_fieldsws.png
In reply to Nicholas Stefanski

Re: core_user_create_users and core_user_update_users are missing some core fields

by Adam M -

I'm also having this issue. I have a customer with Moodle 3.2.x and I can't add phone1 or institution using core_user_create_users. I don't understand why I can update idnumber but not these field.

In reply to Adam M

Re: core_user_create_users and core_user_update_users are missing some core fields

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers

Please vote for my tracker:

https://tracker.moodle.org/browse/MDL-62657

And add the other missing fields in the comments!

In reply to Richard van Iwaarden

Re: core_user_create_users and core_user_update_users are missing some core fields

by Nicholas Stefanski -

Wonderful! I never got around to taking a stab at this myself, but this works retroactively at least back to Moodle 3.4.3 as well. It also happens to fix some weird errors I was getting even with the previously supported "city" and custom fields. Thanks Richard!

Average of ratings: Useful (1)
In reply to Nicholas Stefanski

Re: core_user_create_users and core_user_update_users are missing some core fields

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers

Hi Nicholas,

You are welcome... but can you help me? Which files do I have to replace in Moodle 3.5 to get this working?

I'm not profiting of these changes myself yet...

In reply to Richard van Iwaarden

Re: core_user_create_users and core_user_update_users are missing some core fields

by Nicholas Stefanski -

In 3.4.3, the only file I replaced was user/externallib.php

I guess I should note that I didn't test all the new fields, just `phone1` and I think `institution`. But like I said, before this change some fields like `city`, which were supposedly already supported, were not working at all for me. Putting in your modified user/externallib.php made `city` work too. It also eliminated some unspecified errors using space characters in custom field values.