# Creating user via API

**URL:** https://meta.discourse.org/t/creating-user-via-api/36133
**Category:** Development
**Tags:** rest-api
**Created:** [November 29, 2015, 8:18pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133 "2015-11-29T20:18:49Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![nadermx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nadermx/32/67585_2.png) [@nadermx](https://meta.discourse.org/u/nadermx)
#### Post date: [November 29, 2015, 8:18pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/1 "2015-11-29T20:18:49Z")

</div>

Right now on my discourse set up, I have it set up to invite only, admin must approve users, and allow new registrations.

The issue I am having though is when I create a user via my API I still have to log in and approve the user on the forum.

So I was wondering if I had to uncheck any of those three to be able to make the user and they are auto created but I don’t have to log in to the discourse to approve them.

I don’t want other users to be able to invite other users to join though as I am creating users based on another sites sign ups.

---

<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: [November 30, 2015, 12:47am UTC](https://meta.discourse.org/t/creating-user-via-api/36133/2 "2015-11-30T00:47:00Z")

</div>

Once you create the user through the API, you will need to make another api request to this endpoint to approve them:

```
http://localhost:3000/admin/users/<user_id>/approve

```

Are you using the discourse\_api gem to talk to the API or some other way?

---

<div class="post-metadata">

### Author: ![nadermx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nadermx/32/67585_2.png) [@nadermx](https://meta.discourse.org/u/nadermx)
#### Post date: [December 4, 2015, 8:11am UTC](https://meta.discourse.org/t/creating-user-via-api/36133/3 "2015-12-04T08:11:17Z")

</div>

Thank you, I’m using [pydiscourse](https://github.com/tindie/pydiscourse). Didn’t know you could do approvals. I ended up having to tweak their wrapper to have it work. But now it’s working. Thank you

---

<div class="post-metadata">

### Author: ![vikas027](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikas027/32/121352_2.png) [@vikas027](https://meta.discourse.org/u/vikas027)
#### Post date: [December 22, 2016, 12:55pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/4 "2016-12-22T12:55:53Z")

</div>

> [@blake](#):
>
> you will need to make another api request to this endpoint to approve them:
> 
> [http://localhost:3000/admin/users/&lt;user\_id&gt;/approve](http://localhost:3000/admin/users/&lt;user_id&gt;/approve)

Hello @blake,

Can you please give an example? I tried using this in vain.

```sh
curl -X PUT "http://localhost:3000/admin/users/batman/approve?api_key=<my_api_key>&api_username=vikas"

```

---

<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: [December 22, 2016, 1:08pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/5 "2016-12-22T13:08:37Z")

</div>

try using the `<user_id>` of the user instead of the username?

---

<div class="post-metadata">

### Author: ![vikas027](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikas027/32/121352_2.png) [@vikas027](https://meta.discourse.org/u/vikas027)
#### Post date: [December 22, 2016, 10:06pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/6 "2016-12-22T22:06:41Z")

</div>

> [@blake](#):
>
> try using the \<user\_id\> of the user instead of the username?

Perfect, worked like a charm. I got confused it with username. Thanks much.

Now, the user gets an activation email which I want to avoid, will look around how to avoid that.

---

<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: [December 23, 2016, 12:10am UTC](https://meta.discourse.org/t/creating-user-via-api/36133/7 "2016-12-23T00:10:18Z")

</div>

> [@Creating Active Users via the API gem](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/8):
>
> Theoretically, you could create an account with a fake email address, deactivate, update the email address to the real email, then activate the account.
> 
> Unfortunately, this is too much of a workaround for the project we are working on. We have decided to settle with sending our users 2 emails. Not an ideal workflow.

^ I think that might be how you can get around the activate email thing /shrug

---

<div class="post-metadata">

### Author: ![Vocino](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vocino/32/85136_2.png) [@Vocino](https://meta.discourse.org/u/Vocino)
#### Post date: [April 25, 2017, 5:00pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/8 "2017-04-25T17:00:35Z")

</div>

Sorry to necro this post but it appears to be the most relevant discussion.

I’m currently adding users via the API but they aren’t getting the verification email. Is there something I can add to the response to ensure that this email gets triggered?

I’ve seen people setting `active` to `true` but that’s what I don’t want since I want them to be pruned if they never verify. Setting it to `false` doesn’t seem to trigger the activation email though.

---

<div class="post-metadata">

### Author: ![cck197](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cck197/32/110338_2.png) [@cck197](https://meta.discourse.org/u/cck197)
#### Post date: [December 7, 2018, 9:33pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/9 "2018-12-07T21:33:59Z")

</div>

Hi, I think I’m having similar trouble using the [pydiscourse](https://github.com/bennylope/pydiscourse) module.

If I create a user with `active=true` I get the following response:

```plaintext
{'success': True,
 'active': True,
 'message': 'Your account is activated and ready to use.',
 'user_id': 212}

```

And all seems well on the dashboard:

 ![19%20PM](https://global.discourse-cdn.com/meta/original/3X/2/6/266c1d01b02aebfd1422e04437c14a9a77b95ca4.png)

However, when I attempt to log in using my newly created account I see this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/c/8ccf77fd23fa9c93feefc36ca64a71cf90900a61.png)

Weird! OK, let’s resend the activation email (even though none was sent originally).

The email comes through and I open the link inside:

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/9/59a31323d3dcc9cc8b105134bdfebac80fb07b6c.png)

Only the button doesn’t do anything!

I tried adding an HTTP get to `/admin/users/<user_id>/approve` and the API call returns something sensible, but still I get the “You can’t log in yet” message when I attempt to log in.

Does anyone have any clues as to where I went wrong?

Thank you!

---

<div class="post-metadata">

### Author: ![cck197](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cck197/32/110338_2.png) [@cck197](https://meta.discourse.org/u/cck197)
#### Post date: [December 7, 2018, 10:20pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/10 "2018-12-07T22:20:08Z")

</div>

OK I found this post:

> [@Creating Active Users via the API gem](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/3):
>
> I just spent the better part of today working on this and found a workaround for it. Here’s the process you have to go through to make this work. Create the account and set active=true. Note the user\_id that is provided from the API call. In your above example, the user\_id=7 so we’ll use that in this example. Make an API call to deactivate the user account. It will be something like this: [http://discourseURL/admin/users/7/deactivate.json?api\_key=xxxx&api\_username=yyyy](http://discourseURL/admin/users/7/deactivate.json?api_key=xxxx&api_username=yyyy) Make an API call to act…

If I do the create/deactivate/activate trick the click here to activate your account button works but I still can’t log in with `active=true`.

---

<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: [August 5, 2020, 2:06pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/11 "2020-08-05T14:06:49Z")

</div>

With this fix, you can now create an active user with a single api request and they won’t receive an email confirmation.

[https://github.com/discourse/discourse/commit/fec68d3d25bfc80d084af52e17882ad886fd5cd0](https://github.com/discourse/discourse/commit/fec68d3d25bfc80d084af52e17882ad886fd5cd0)

---

<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: [September 4, 2020, 2:06pm UTC](https://meta.discourse.org/t/creating-user-via-api/36133/12 "2020-09-04T14:06:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
