wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
340 stars 130 forks source link

Unable to Update a User #248

Open Cory05 opened 3 years ago

Cory05 commented 3 years ago

I am able to retreive a user. The username is always null, even though it is set in the WordPress site. Attempting to update any data with the user raises the error WPException: Invalid parameter(s): username. The code is pretty straight forward.

WordPressPCL.Models.User user = await client.Users.GetByID(21); user.NickName = "Jane Smithy"; await client.Users.Update(user);

Is this a bug?

Thanks.

stevecurrey commented 3 years ago

I also have this error. Appears to be a bug. Not sure how else to update user details.

stevecurrey commented 3 years ago

@Cory05 if you know the username of the user, you can build a query as a workaround.

var userQuery = new UsersQueryBuilder { Context = WordPressPCL.Models.Context.Edit, //another conditions }; var usersWithUsername = await client.Users.Query(userQuery, true);

You can then set the username and the field you are trying to edit and save the user.

stevecurrey commented 3 years ago

I have just noticed that client.Users.Update(user); passes NULL as email.

There is no way to update a user at the moment.

fengfranklu commented 2 years ago

I am trying to retrieve the email address of a user, but the email is always null. Could this may be related??

simonhammes commented 6 months ago

I am able to retreive a user. The username is always null, even though it is set in the WordPress site.

I am trying to retrieve the email address of a user, but the email is always null. Could this may be related??

WordPress only exposes a user's username and email address if context=edit (see https://developer.wordpress.org/rest-api/reference/users/ for details).

This is related to https://github.com/wp-net/WordPressPCL/issues/266.