Auto generate password for account created through API?

I’m developing a little script that creates user account through discourse API. The create API doesn’t allow user creation without passing a password.

It would be nice if the API creates the user even if no password is specified and when activating the user is asked for his password.

Is it the kind of feature that could be added or is there already a better way to do that ? (or did I missed an option in the admin panel ?)

So you are going to send email to activate the user? If yes then it’s better to send invites instead of creating accounts via API. Because invitations will activate the user instantly when they accept it and the password reset email will be sent.

1 Like

Oh, I didn’t know invites worked this way. I’m going to look into it, thanks :wink:

The API about invitation is not well presented in the documentation… I guess I’ll have to read the code to find out how it works.

Is there a way to accept the invitation for the user and just send him the “reset password” mail ? The goal here is to easily add a willing user without asking him to set his password directly. In our case, we have a contact form on our website (with name, email and message) bearing a checkbox “register me on the forum”.

So I’d like the server handling the form to add the user to discourse though API.

Can’t you ask for password and confirm password when a user click the “register me on the forum” checkbox?

So you can even bypass password resetting email.

We could do that, but the form handler isn’t yet behind a SSL layer so I’d rather have Discourse handling the password.
So I thought that if there was a way to do that more or less easily directly in Discourse it would be better. If not, I’ll fall back to your proposal :wink:

Okay I understand. What is the problem you are facing with Invites API?

I hardly find any documentation about it, I did some try and retry on some guessed usage but I always ends up with “502 Bad Gateway”.

I tried:

  • POST /invites
  • POST /admin/invites
  • POST /invite

I don’t get what’s the expected path and params for invitation.

I looked into https://github.com/discourse/discourse_api/blob/master/routes.txt but I don’t understand how to read it…

https://github.com/discourse/discourse_api/blob/master/lib/discourse_api/api/invite.rb#L5

as per official Ruby API client code POST /invites is correct I guess.

1 Like

Ok, with a “email” field in the params it doesn’t do the gateway error. I manage to create an invite that way.

I’ll try to create a user with a random password and trigger the password reset action to see if I can achieve my goal this way :rolling_eyes: