# Example Code in PHP how to Create a new User

**URL:** https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186
**Category:** Development
**Created:** [October 16, 2017, 3:14pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186 "2017-10-16T15:14:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mertins-mir](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mertins-mir/32/81852_2.png) [@mertins-mir](https://meta.discourse.org/u/mertins-mir)
#### Post date: [October 16, 2017, 3:14pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186/1 "2017-10-16T15:14:36Z")

</div>

Hi all,

I’ve got an existing User DB and I simply want to push the User into the discourse Forum. My programming language is PHP and I know how to use curl but are there any examples, how to push a new user into discourse?

That would help me a lot.

Thanks! Frank

---

<div class="post-metadata">

### Author: ![MakaryGo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/makarygo/32/187426_2.png) [@MakaryGo](https://meta.discourse.org/u/MakaryGo)
#### Post date: [October 16, 2017, 3:38pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186/2 "2017-10-16T15:38:51Z")

</div>

Wouldn’t it be easier to use import script? This importer can be an excellent base to make your own, just change DB table and row names from PHPBB’s to yours, and comment out anything that is not user-related: [Migrate a phpBB3 forum to Discourse](https://meta.discourse.org/t/importing-from-phpbb3/30810) 🙂

---

<div class="post-metadata">

### Author: ![mertins-mir](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mertins-mir/32/81852_2.png) [@mertins-mir](https://meta.discourse.org/u/mertins-mir)
#### Post date: [October 16, 2017, 3:56pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186/3 "2017-10-16T15:56:23Z")

</div>

Hm, I don’t have shell access to discourse because it is maintained by someone else.

---

<div class="post-metadata">

### Author: ![MakaryGo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/makarygo/32/187426_2.png) [@MakaryGo](https://meta.discourse.org/u/MakaryGo)
#### Post date: [October 16, 2017, 4:15pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186/4 "2017-10-16T16:15:36Z")

</div>

Okay, got it.  
As the [docs.discourse.org](http://docs.discourse.org) states, you have to make a `POST` request to the address `yourforum/users` with this fields:

```json
{
  "name": "string",
  "email": "string",
  "password": "string",
  "username": "string",
  "active": true,
  "approved": true,
  "user_fields[1]": "string"
}

```

In this request, fields that you **have to** send are: `name, email, password and username`.  
As this is a `POST` request, even simple HTML form should be enough, if I understand well 🙂

---

<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: [October 16, 2017, 4:57pm UTC](https://meta.discourse.org/t/example-code-in-php-how-to-create-a-new-user/72186/5 "2017-10-16T16:57:17Z")

</div>

An import script is usually the easiest way to import users.

> [@mertins-mir](#):
>
> I don’t have shell access to discourse because it is maintained by someone else.

But they’ll give you an API key for the site?

Do you have admin access? Is it a new community or are there existing posts? Could you do the import and restore a backup?

One solution might just be to do a bulk invite.
