Programmatically inviting users

(Phil Nelson) #1

We have a need to invite about 100 users (and eventually about 3000 more) to our discourse install, and my ruby/rails is super rough. I searched around on the forums and couldn’t find a good example. How might someone invite users to the forums in an automated way, from a list or even just on the command line? I’m not even really worried about sending an invite email, but creating the user and assigning an invite code.

(Sam Saffron) #2

See our discourse_api gem. There is a sample for it:

(Phil Nelson) #3

Thanks for the quick reply! Now I just need to disable invite emails temporarily while I generate these…

(Kane York) #4

Don’t forget that invites expire!

(Phil Nelson) #5

Currently stumbling pretty hard on this one. The example for inviting users works up until the last line, and then I get:

NoMethodError: undefined method `topic_invite_user' for #<DiscourseApi::Client:0x007f9f2106bf90>

(Sam Saffron) #6

yeah … the gem needs to be installed, that is the simplest thing

have you tried installing the gem?

(Phil Nelson) #7

Boy, I was being pretty dumb there.

I got it working but had to modify the gem a bit. Looks like some variables got renamed inside Discourse (and some variable names don’t match in the gem .vs. the examples!). I’ll try to submit a pull request later today if I get some time.

(Erlend Sogge Heggen) #8

Did you end up making that pull request? We have a need for this as well now so it’d be interesting to see what your code ended up looking like.

(Phil Nelson) #9

Sorry- I couldn’t find the time and now the code has changed enough that it might not work. I have to figure this out again and will hopefully be able to post some useful code when I do.

(Alasdair Young) #10

I have a website written in java. When the user signs up to my site I’d also like them to get an invite to the discourse-based forums running on another server. Obviously I can’t use a ruby-based API on my java server - is there a rest API available (with docs)? Or even just documentation on the exact form parameters that I’d need to post?