# Add user to group via webhook with email

**URL:** https://meta.discourse.org/t/add-user-to-group-via-webhook-with-email/265305
**Category:** WordPress
**Created:** [May 17, 2023, 9:44am UTC](https://meta.discourse.org/t/add-user-to-group-via-webhook-with-email/265305 "2023-05-17T09:44:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![illusionandcards](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/illusionandcards/32/306500_2.png) [@illusionandcards](https://meta.discourse.org/u/illusionandcards)
#### Post date: [May 17, 2023, 9:44am UTC](https://meta.discourse.org/t/add-user-to-group-via-webhook-with-email/265305/1 "2023-05-17T09:44:36Z")

</div>

Good day,

I am trying to add users from Wordpress to private groups in Discourse via webhook.

I use [WP Discourse](https://github.com/discourse/wp-discourse) plugin as a SSO login method and I don’t allow users to change their username in Discourse. I made this because I thought that this way I could use the username from Wordpress to add them to a group in Discourse. Because, I thought they would be the same.

The problem is that when the username is generated automatically in Wordpress, sometimes uses their email as their username. But Discourse doesn’t allow this in usernames, so it breaks the username at “@”.

> Example:  
> Wordpress email: [jhon@gmail.com](mailto:jhon@gmail.com)  
> Wordpress username (generated automatically): [jhon@gmail.com](mailto:jhon@gmail.com)  
> Discourse username (generated through [WP Discourse](https://github.com/discourse/wp-discourse) SSO): jhon

This is not allowing me to use the wordpress user to add them to a group.

Is there an easier way to make this?

It would be awesome to be able to add users to a group with their email instead of username. The email is always available in any app (CRM, Wordpress, etc), so it won’t be needed the extra step to make a “GET” request to the API to get the username from that email and then PUT them in the group.

I use Fluent Forms to send this data to the webhook from Wordpress when they send a form, so I can’t make the GET request and then PUT the username.

Thank you!

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 17, 2023, 11:26am UTC](https://meta.discourse.org/t/add-user-to-group-via-webhook-with-email/265305/2 "2023-05-17T11:26:11Z")

</div>

If I’m understanding you correctly, you’re doing this

1. Using [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) with Wordpress as the provider and Discourse as the client.
2. Using a Webhook in Wordpress to put users in groups in Discourse (.e. PUT to /g/:group\_name/members ([api ref](https://docs.discourse.org/#tag/Groups/operation/addGroupMembers))) as a result of a form action.

if that’s right you can find the Discourse username in Wordpress in the `discourse_username` user meta field, so

```plaintext
get_user_meta($user_id, 'discourse_username', true);

```

Use that to get the username to use in the PUT request following the form action.

You can ensure that `discourse_username` is filled for your users using the user webhooks in the [WP Discourse](https://github.com/discourse/wp-discourse) plugin (note we’re talking about different webhooks from the ones you’re currently using in your form).

 ![Screenshot 2023-05-17 at 13.23.23](https://global.discourse-cdn.com/meta/original/4X/7/2/d/72dfd777bbdbc20e909f4553a4a23b93f4b9f9b0.png)
