# Changing a user's email address via api

**URL:** https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027
**Category:** Development
**Tags:** rest-api
**Created:** [March 14, 2016, 4:43pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027 "2016-03-14T16:43:27Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![paully21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paully21/32/72673_2.png) [@paully21](https://meta.discourse.org/u/paully21)
#### Post date: [March 14, 2016, 4:43pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/1 "2016-03-14T16:43:27Z")

</div>

We have a section on our website that allows users to manage their Discourse account preferences. Most of our users only use Discourse as a sort of mailing list, so we made it easy for them to manage that activity within their website account.

I need to be able to modify the user’s email address via an api call. We do all sorts of stuff with api calls now, but I can’t figure out how to change the email address.

I’m guessing I need the update action of the `UsersEmailController` ([https://github.com/discourse/discourse/blob/master/app/controllers/users\_email\_controller.rb](https://github.com/discourse/discourse/blob/master/app/controllers/users_email_controller.rb)) but I don’t know how to reach that endpoint.

Does anyone know the URL of the endpoint to change a user’s email address (using the api key and api username method)?

Thanks!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 14, 2016, 4:46pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/2 "2016-03-14T16:46:59Z")

</div>

Did you try:

`PUT https://meta.discourse.org/users/falco/preferences/email`

with `email` parameter?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [March 14, 2016, 4:48pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/3 "2016-03-14T16:48:41Z")

</div>

> [@paully21](#):
>
> Does anyone know the URL of the endpoint to change a user’s email address (using the api key and api username method)?

If you look at the [`routes.rb`](https://github.com/discourse/discourse/blob/master/config/routes.rb#L296) file you will see this line

```ruby
put "users/:username/preferences/email" => "users_email#update", constraints: {username: USERNAME_ROUTE_FORMAT}

```

which means you need to `PUT https://your.discourse.org/users/<username>/preferences/email`

_Got ninja-ed by @Falco 😉_

---

<div class="post-metadata">

### Author: ![paully21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paully21/32/72673_2.png) [@paully21](https://meta.discourse.org/u/paully21)
#### Post date: [March 14, 2016, 4:49pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/4 "2016-03-14T16:49:08Z")

</div>

Yep…And I got a 200 OK, but it didn’t change the email address in Discourse.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 14, 2016, 4:50pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/5 "2016-03-14T16:50:13Z")

</div>

Looks like it send an e-mail for confirmation! Did you get one 📧 ?

---

<div class="post-metadata">

### Author: ![paully21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paully21/32/72673_2.png) [@paully21](https://meta.discourse.org/u/paully21)
#### Post date: [March 14, 2016, 4:52pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/6 "2016-03-14T16:52:19Z")

</div>

It does send a confirmation…Ah…So it works and I had it correct. I guess I’m not going crazy.

Now, is there a way to _not_ send the confirmation and just confirm it straight away?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 14, 2016, 4:54pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/7 "2016-03-14T16:54:04Z")

</div>

> [@paully21](#):
>
> Now, is there a way to not send the confirmation and just confirm it straight away?

I don’t think so, unless you wanna mess without the api.

But confirmations are good to stop typos!

---

<div class="post-metadata">

### Author: ![paully21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paully21/32/72673_2.png) [@paully21](https://meta.discourse.org/u/paully21)
#### Post date: [March 14, 2016, 5:05pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/8 "2016-03-14T17:05:58Z")

</div>

Cool…Thanks for all the help!

Paul

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 28, 2018, 7:13am UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/9 "2018-12-28T07:13:51Z")

</div>



---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [December 28, 2018, 5:45pm UTC](https://meta.discourse.org/t/changing-a-users-email-address-via-api/41027/10 "2018-12-28T17:45:32Z")

</div>


