Example Code in PHP how to Create a new User


(Frank Mertins) #1

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


#2

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: Importing from phpBB3 :slight_smile:


(Frank Mertins) #3

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


#4

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

{
  "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 :slight_smile:


(Jay Pfaffman) #5

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

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.