# Creating Active Users via the API gem

**URL:** https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133
**Category:** Development
**Tags:** rest-api
**Created:** [9월 11, 2015, 6:06오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133 "2015-09-11T18:06:38Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2월 23, 2017, 2:54오전 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/22 "2017-02-23T02:54:14Z")

</div>

> [@joshfrank](#):
>
> My forum is a tool for members of an organization. They know they joined the organization, and they get a manual email from someone else welcoming them.

Since you are manually sending an email from your org could you create a random password using the api and put that password in that email? Then you could encourage them to reset the password after they have started to use the forum.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2월 23, 2017, 2:59오전 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/23 "2017-02-23T02:59:13Z")

</div>

WordPress does this random password thing, I believe. So the precedent is there.

---

<div class="post-metadata">

### Author: ![joshfrank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshfrank/32/114706_2.png) [@joshfrank](https://meta.discourse.org/u/joshfrank)
#### Post date: [2월 23, 2017, 3:11오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/24 "2017-02-23T15:11:36Z")

</div>

> [@blake](#):
>
> could you create a random password using the api and put that password in that email?

I’m already creating the random password and I could send that info in the manual email. But it still doesn’t enable the workflow I need:

- If I create the user and don’t also approve her, when she tries to log in using the new credentials, Discourse gives a message that says she must be approved.
- If I create the user and also approve her, Discourse sends the activation email that I don’t want to send.

And even if I could work around that, I’d still have to send instructions like “Log in using this usr/pwd and then go a certain topic (which you don’t know how to do because you’ve never used this before)”. I’d much prefer to create a link like `http://example.com/magic_token` which would at least log them in and ideally redirect to a topic of my choosing.

At this point, I’m still evangelizing for Discourse in this organization, so the users aren’t coming to me, I’m selling to them. Every extra bit of effort required by these mostly non-technical people is losing me users or, at best, injecting annoyance and tech support emails.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2월 23, 2017, 3:35오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/25 "2017-02-23T15:35:02Z")

</div>

> [@joshfrank](#):
>
> If I create the user and also approve her, Discourse sends the activation email that I don’t want to send.

There currently is no “supported” way to do this in Discourse it doesn’t exist.

To get around activating a user without sending an email you have to do some weird hacks like create the user with a fake email, activate, let discourse send the email to the fake account then swap the fake email address with the real one. Or you have to activate and then deactivate the user like mentioned above.

---

<div class="post-metadata">

### Author: ![joshfrank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshfrank/32/114706_2.png) [@joshfrank](https://meta.discourse.org/u/joshfrank)
#### Post date: [2월 23, 2017, 3:39오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/26 "2017-02-23T15:39:59Z")

</div>

I am coming to accept this, but I’m a little puzzled about why this should be so hard. I know this probably isn’t a common use case for forum user invitation, but it doesn’t seem totally bizarre either.

In this thread, it doesn’t sound like the activate/deactivate approach really works, and anyway activating does NOT send the email, it’s **approval** that sends the email, which is also a bit confusing.

---

<div class="post-metadata">

### Author: ![joshfrank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshfrank/32/114706_2.png) [@joshfrank](https://meta.discourse.org/u/joshfrank)
#### Post date: [2월 23, 2017, 3:41오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/27 "2017-02-23T15:41:04Z")

</div>

> [@ryanwanger](#):
>
> What is the best approach for me?

@ryanwanger: Did you ever solve this problem or find an acceptable workaround? I’m struggling with the same problem.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2월 23, 2017, 3:53오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/28 "2017-02-23T15:53:38Z")

</div>

> [@joshfrank](#):
>
> I’m a little puzzled about why this should be so hard

It’s only because its not a core feature of the actual Discourse web workflow and nobody has spent ANY time on it. It’s on my personal list to work on, just haven’t been able to get to it. PR’s are welcome.

---

<div class="post-metadata">

### Author: ![joshfrank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshfrank/32/114706_2.png) [@joshfrank](https://meta.discourse.org/u/joshfrank)
#### Post date: [2월 23, 2017, 4:28오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/29 "2017-02-23T16:28:47Z")

</div>

I would love to pitch in but I’m not a Ruby programmer. I’d have to start with hello, world and it’d be quite some time before my commits would be useful. ☹

It sounds like it doesn’t send the email if `Must approve new users` is disabled. But I’m not of the other implications of this. If I disable this, can I still make it so that users can’t create accounts?

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [2월 23, 2017, 6:53오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/30 "2017-02-23T18:53:35Z")

</div>

You can disable signups by enabling `invite only`, which only allows users to sign up if they have an invite from a staff or community member.

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [2월 27, 2017, 1:50오전 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/31 "2017-02-27T01:50:10Z")

</div>

> [@joshfrank](#):
>
> I am coming to accept this, but I’m a little puzzled about why this should be so hard. I know this probably isn’t a common use case for forum user invitation, but it doesn’t seem totally bizarre either.

I have this need in 3/4 of the forums I run, the 4th forum uses the more common solution: login via SSO to the site they already know.

In the other 3 orgs, there isn’t an SSO provider I can rely on, so I’m in the same boat here. I think that sending a temp, must be reset password, is an OK solution here.

---

<div class="post-metadata">

### Author: ![anon36484860](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@anon36484860](https://meta.discourse.org/u/anon36484860)
#### Post date: [5월 16, 2017, 12:33오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/32 "2017-05-16T12:33:54Z")

</div>

I am struggling with same issue!

When creating a user with API, a confirmation email is sent which I want to prevent. The account is activated with the API already. Not only the email becomes redundant - the activation link is not even working. That confuses the user.

Would be great to get an option to disable activation email for API user registration!

---

<div class="post-metadata">

### Author: ![skodali](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@skodali](https://meta.discourse.org/u/skodali)
#### Post date: [12월 5, 2017, 3:17오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/33 "2017-12-05T15:17:06Z")

</div>

Were you able to find a solution to this issue? I am also running into the same issue.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [12월 6, 2017, 2:37오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/34 "2017-12-06T14:37:46Z")

</div>

~~To create an active user you will need to make two api calls. The first to create the user and the second to activate them.~~

> [@Disable account confirm emails when creating users via API](https://meta.discourse.org/t/disable-account-confirm-emails-when-creating-users-via-api/68663/31):
>
> They might be under the “new” tab instead of the “active” tab? I’m not exactly sure what your use case is for creating users for the API but I would consider looking into using [Single Sign on](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045). However, these are the current steps you need to perform in order to create a user via the API without sending a confirmation email. You will have to make 3 requests: Create the user with the active=true param Deactive the user Activate the user.

---

<div class="post-metadata">

### Author: ![skodali](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@skodali](https://meta.discourse.org/u/skodali)
#### Post date: [12월 18, 2017, 4:54오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/35 "2017-12-18T16:54:54Z")

</div>

When I create the user using the create user API it sends out an email to the user to activate the account. Ideally I don’t want the system to do it as I will be activating the user with the activateuser api call. They one solution that I can find is to create the user, deactivate the user and then activate the user again so that the system wont send an email to the user.

---

<div class="post-metadata">

### Author: ![mikechristopher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mikechristopher/32/89135_2.png) [@mikechristopher](https://meta.discourse.org/u/mikechristopher)
#### Post date: [2월 8, 2018, 2:50오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/36 "2018-02-08T14:50:43Z")

</div>

I believe this is now possible as have just tested it and seems to work ok -

```plaintext
{
"name": "string",
"email": "string",
"password": "string",
"username": "string",
"active": true,
"approved": true,
}

```

> **[Discourse API Docs](https://docs.discourse.org/#tag/Users%2Fpaths%2F~1users%2Fpost)**

I used the **active = true** and **approved = true** when creating a new user and got the response (with no email sent) -

```plaintext
    {
        "success": true,
        "active": true,
        "message": "Your account is activated and ready to use.",
        "user_id": 2
    }

```

where as if I set them to false - I get the email and a response

```plaintext
{
    "success": true,
    "active": false,
    "message": "<p>You’re almost done! We sent an activation mail to <b>###@gmail.com</b>. Please follow the instructions in the mail to activate your account.</p><p>If it doesn’t arrive, check your spam folder.</p>",
    "user_id": 3
}

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2월 8, 2018, 5:19오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/37 "2018-02-08T17:19:46Z")

</div>

Hmm. When I did this last week, I did the deactive, then activate thing. Adding “approved=true” is a good idea. I’m not sure that it matters unless the site requires approval, but I don’t see how it could hurt.

Here’s my solution:

[https://github.com/pfaffman/discourse-user-creator](https://github.com/pfaffman/discourse-user-creator)

---

<div class="post-metadata">

### Author: ![paulmwatson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paulmwatson/32/114226_2.png) [@paulmwatson](https://meta.discourse.org/u/paulmwatson)
#### Post date: [10월 16, 2018, 6:53오전 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/39 "2018-10-16T06:53:21Z")

</div>

I sent active and approved and emailed\_confirmed as true just in case, got back “Your account is activated and ready to use” in the response but when I tried to login as that user it said “You can’t log in yet. We previously sent an activation email to you…”

The `email_confirmed` is what needs to be set but is not accepted via the API. Seems like a second activation call is the current way to do it.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [9월 18, 2019, 4:35오전 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/40 "2019-09-18T04:35:04Z")

</div>

> [@paulmwatson](#):
>
> The `email_confirmed` is what needs to be set but is not accepted via the API. Seems like a second activation call is the current way to do it.

Do we still need to deactivate and activate to create active user withought sending confirmation email?

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [12월 27, 2019, 12:19오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/41 "2019-12-27T12:19:04Z")

</div>

관리자 패널을 통해 사용자가 즉시 활성화된 상태로 생성되도록 설치할 수 있나요?

내 플러그인에서 사용자 활성화를 위해 어떤 메서드를 사용해야 하나요?

 ![2019-12-27_152008](https://global.discourse-cdn.com/meta/original/3X/e/3/e39dcb9dbea887aec8d65098199eaabb827bee37.png)

# 플러그인 코드에서

`user.save `  
다음 단계는 무엇인가요?

upd: `user.approved`

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [8월 5, 2020, 1:57오후 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/43 "2020-08-05T13:57:50Z")

</div>

이 커밋으로 해결되었습니다:

> <https://github.com/discourse/discourse/commit/fec68d3d25bfc80d084af52e17882ad886fd5cd0>
>
> This commit is for a frequently requested task on meta so that only 1
> API call i…s needed instead of 3!
> 
> In order to create a user via the api and not have them receive an
> activation email you can pass in the \`active=true\` flag. This prevents
> sending an email, but it is only half of the solution and puts the db in
> a weird state where it has an active user with an unconfirmed email.
> 
> This commit fixes that and ensures that if the \`active=true\` flag is set
> the user's email is also marked as confirmed.
> 
> This change only applies to admins using the API.
> 
> Related topics on meta:
> 
> - https://meta.discourse.org/t/-/68663
> - https://meta.discourse.org/t/-/33133
> - https://meta.discourse.org/t/-/36133

[Previous page](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133.md?page=1)

[Next page](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133.md?page=3)
