Example Code in PHP how to Create a new User

AI-generated summary

The discussion revolves around creating a new user in Discourse using PHP. mertins-mir asks for an example of how to push a user into Discourse via PHP using cURL, as they have an existing user database. MakaryGo suggests using an import script as a starting point, referencing a PHPBB3 importer, but acknowledges mertins-mir lacks shell access. MakaryGo then provides details on the required POST request to the /users endpoint, listing necessary fields like name, email, password, and username, noting that a simple HTML form could suffice. pfaffman reiterates that import scripts are typically easiest and questions whether mertins-mir has admin access or an API key, suggesting alternatives like bulk invites or restoring a backup.

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

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

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

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:

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.