# Automatically add users to groups based on custom field value

**URL:** <https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858>\
**Category:** Feature\
**Tags:** automation, completed, user-custom-fields\
**Created:** [May 6, 2018, 3:59am UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858 "2018-05-06T03:59:39Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![li-zi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/li-zi/32/161339_2.png) [@li-zi](https://meta.discourse.org/u/li-zi)\
**Post date:** [November 22, 2019, 1:51am UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/4 "2019-11-22T01:51:06Z")

</div>

For anybody coming across this in the future: I had a similar use case (two distinct user populations – people offering services vs. people seeking services) and ended up implementing it via webhooks and the Discourse API.

More specifically, I…

- created a webhook triggered on user events
- implemented a barebones Express.js server to receive the payload
- set up a POST route for `user_created` events that checks the value of a custom user field, and then uses the Discourse API to set the user’s group accordingly

This seems like kind of a goofy way to do it because I’m going outside Discourse to modify something within Discourse, but I scoured the forum for answers to this and came up with nothing, so I did my best! Hope this helps someone in the future, and if anyone comes up with a better way of doing it, I’d love to know.

---

_[View the full topic](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858)._
