Populate additional fields when creating a user using Write API

Solved NodeBB Development
  • #1

    Hello everyone!

    I'm creating users in NodeBB instance from another Node.js application using NodeBB Write API plugin.

    According to the documentation POST /api/v1/users/ accepts only username, password, email fields and "Any other data passed in will be saved into the user hash".

    My questions are: What is actually user hash in context of NodeBB? And is it possible at all to populate any other fields than username, password, email when creating a user using Write API?

  • NodeBB

    In nodebb the user hash is just the user object. The name comes from the redis hashes. If you are using redis you can see the data in the hash with hgetall user:<user_id>

  • #3

    Thank you for response!

    No, I'm using mongo instead of redis. I'm just wondering how can I write additional fields like fullname, location etc. using Write API. Should I firstly create a user with POST /api/v1/users/ and then make additional API call PUT /api/v1/users/:uid in order to populate additional user fields?

  • NodeBB

    Yes that should work since fullname and location are core fields, if you need to add additional fields that don't exist in core then you would need to write a plugin to add those fields using hooks like filter:user.updateProfile

  • #5

    Thanks a lot for your assistance. The filter filter:user.updateProfile seems to be very useful for my needs.

  • #6

    @baris Hi, i too have the same requirement, i understand that we have to write a plugin to use the hooks filter:user.updateProfile.

    Could you please provide any sample to write plugin and use this hook.

Suggested Topics

| | | |