Creating user via API


(Johnathan Nader) #1

Right now on my discourse set up, I have it set up to invite only, admin must approve users, and allow new registrations.

The issue I am having though is when I create a user via my API I still have to log in and approve the user on the forum.

So I was wondering if I had to uncheck any of those three to be able to make the user and they are auto created but I don’t have to log in to the discourse to approve them.

I don’t want other users to be able to invite other users to join though as I am creating users based on another sites sign ups.


(Blake Erickson) #2

Once you create the user through the API, you will need to make another api request to this endpoint to approve them:

http://localhost:3000/admin/users/<user_id>/approve

Are you using the discourse_api gem to talk to the API or some other way?


(Johnathan Nader) #3

Thank you, I’m using pydiscourse. Didn’t know you could do approvals. I ended up having to tweak their wrapper to have it work. But now it’s working. Thank you


(Vikas) #4

Hello @blake,

Can you please give an example? I tried using this in vain.

curl -X PUT "http://localhost:3000/admin/users/batman/approve?api_key=<my_api_key>&api_username=vikas"

(Blake Erickson) #5

try using the <user_id> of the user instead of the username?


(Vikas) #6

Perfect, worked like a charm. I got confused it with username. Thanks much.

Now, the user gets an activation email which I want to avoid, will look around how to avoid that.


(Blake Erickson) #7

^ I think that might be how you can get around the activate email thing /shrug


(Travis) #8

Sorry to necro this post but it appears to be the most relevant discussion.

I’m currently adding users via the API but they aren’t getting the verification email. Is there something I can add to the response to ensure that this email gets triggered?

I’ve seen people setting active to true but that’s what I don’t want since I want them to be pruned if they never verify. Setting it to false doesn’t seem to trigger the activation email though.


(Christopher Kelly) #9

Hi, I think I’m having similar trouble using the pydiscourse module.

If I create a user with active=true I get the following response:

{'success': True,
 'active': True,
 'message': 'Your account is activated and ready to use.',
 'user_id': 212}

And all seems well on the dashboard:

However, when I attempt to log in using my newly created account I see this:

Weird! OK, let’s resend the activation email (even though none was sent originally).

The email comes through and I open the link inside:

Only the button doesn’t do anything!

I tried adding an HTTP get to /admin/users/<user_id>/approve and the API call returns something sensible, but still I get the “You can’t log in yet” message when I attempt to log in.

Does anyone have any clues as to where I went wrong?

Thank you!


(Christopher Kelly) #10

OK I found this post:

If I do the create/deactivate/activate trick the click here to activate your account button works but I still can’t log in with active=true.