# 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:** [2015 年 9 月 11 日午後 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:** 1
**Showing post:** 16

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2017 年 1 月 23 日午後 3:33 UTC](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133/16 "2017-01-23T15:33:15Z")

</div>

I looked into this and the best way to create a “pre-activated” (ready to login) user account is to first create a user and activate it _just after_ the user is created.

Here is how to do it via official [discourse\_api](https://github.com/discourse/discourse_api) gem:

```ruby
# create user
user = client.create_user(
  name: "Bruce Wayne",
  email: "bruce@wayne.com",
  username: "batman",
  password: "WhySoSerious"
)

# activate user
client.activate(user["user_id"])

```

Here is how to do it via cURL request:

```bash
# create user
curl -X POST --data "name=dave&username=dave&email=dave@example.com&password=daveIsAwesome&api_key=x1y2z3&api_username=xyz" http://discourse.example.com/users

# activate user
curl -X PUT "http://discourse.example.com/admin/users/{USER_ID}/activate.json?api_key=x1y2z3&api_username=xyz"

```

---

_[View the full topic](https://meta.discourse.org/t/creating-active-users-via-the-api-gem/33133)._
