Update users info via API or CLI

Hello!
Have been digging in docs for few days and get stuck on my task.

Is there is a way I can change user password/login/email without UI but via API?

I have a dump of Wiki and have to update users email and password with current ones.

Will deeply appreciate if you’ll show me the way I can create and send request to the Wiki.

PS I have previous and current admin credentials if it is needed

Hi,

We started to work on a User API for this kind of things, but right now it doesn’t allow to change user password. The documentation is there: https://extensions.xwiki.org/xwiki/bin/view/Extension/User%20Module/API/ and what you need to manipulate is UserProperties, defined here: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-api/src/main/java/org/xwiki/user/UserProperties.java

Now note that each user in XWiki is an XWikiDocument with a dedicated xobject of type XWikiUser, so basically you can just manipulate the documents to perform the changes you need if UserProperties doesn’t expose enough API or if you’re using an older wiki. Don’t hesitate to submit any feature request to improve this API on https://jira.xwiki.org.

Hope that helps.

Thank you very much for a fast answer!

Your notes will help for sure. Though could you please be so kind to explain, where exactly to use it?
As I understand, I will need to create JS-script and than run it “For example from a Java component”.
But what is Java component here and what way I can pass script to it?

The easiest way to manipulate the API I pointed is by using a velocity or a groovy script in XWiki. You can find documentation about scripting in XWiki there: https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/

Note that you might be able to do what you want just by using the REST API documented here: https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiRESTfulAPI#HObjectresources
As I said previously since users are xobjects in a document, you are able to modify the properties of those objects. Now you have to dig a bit to find exactly the names of the properties you want to modify etc.

Thanks for you help!

Will check links you have provided and try to finish my task.

Have a nice day! =)

And hello again)
Here https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-api/src/main/java/org/xwiki/user/UserProperties.java I can use several properties for my aim, but there is still problem with a password.

As far as I can see there is no property I can use for it. I’ve searched on code and see some scripts for updating and reseting passwords, but no one from them seems to be useful in my situation.

Is it possible at all to change it not from UI?

Yes, this is not implemented currently.

Yes, you need to change the password xproperty of the XWikiUsers xobject in the user doc.

See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/XWikiVelocityTraining/#HManipulationofXObjects for example.

Ok, thanks, probably I as usual choose the most complicated way. Will try to follow your advice)