@Brutus5000 said in How to change user name via external call?
2. I have no clue how to do this with the plugin system. From my understanding the hook system can only be triggered when actions are executed inside nodeBB. But in this case the action would be triggered from a 3rd party system without a user being logged in.
Well, fortunately for you, you are wrong. Hooks are really just triggers - if x happens call every function that is using that hook. But there is no problem with using something else to trigger your plugin.
A relatively common example would be websockets, that can be used to send data from frontend to backend when there is no hook covering what you want to get.
So as long as there is a way to communicate between your service and your NodeBB plugin there shouldn't be any problem there.
Now, as for
- I have not seen any documentation on changing usernames via plugin.
Unfortunately, there is not a lot of documentation on NodeBB internals so you mostly need to just look at the source and find what you need.
In this case the functions you need are in
src/user, so you can import them with
const user = require.main.require('./src/user');.
To update the username you will need a function from
But to do that you will need their uid - while I assume you only start with their (old) username. Fortunately there is a function
src/user/index.js that works just like the name suggests.
There is also another way to do what you want, however. There is a (write api plugin)[https://github.com/NodeBB/nodebb-plugin-write-api] you can use to change the username without writing your own plugin. Just get the uid from the standard read api (
your.forum.com/api/user/userslug) and then make a
PUT request to
:uid with the uid from the previous step, obviously).