Creating user via API

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.

2 Likes

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?

8 Likes

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

4 Likes

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"
1 Like

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

3 Likes

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.

1 Like

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

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.

1 Like

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!

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.

With this fix, you can now create an active user with a single api request and they won’t receive an email confirmation.

https://github.com/discourse/discourse/commit/fec68d3d25bfc80d084af52e17882ad886fd5cd0

6 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.