Invite token bulk email API sample


(Sam Saffron) #1

@codinghorror started a sister topic on general improvements to the invite system.

In some cases these changes just will not cut it.

  • In some cases people may want to send out a batch of invites via a third party tool, mailchimp, boomerang and so on. Many of these platforms are designed for email spam and provide better feedback and statistics.

  • In some cases people may want complete control over, subject and body of the email. They may want to include custom copy that differs to the standard email.

To achieve this we need to amend our API endopoint to allow for generation of tokens.

The spec is quite simple:

  1. Input is the exact same format our CSV invite takes
  2. Output is a CSV containing emails and invite links


gem install discourse_api
discourse_api --key API_KEY --username USER generate_invite_tokens INPUT.CSV > OUPTUT.CSV

Side project here is making the api gem more usable, having it distribute a binary to run all sorts of tasks like this.


@techAPJ will be working on this after he is done with general invite improvements.

Feedback @stevebaer @bobmcneel ?

(Steve Baer) #2

Let me make sure I’m interpreting this correctly. From what I reading, the API call will take a CSV file that contains a list of (email,groups,topic_id)

When the API call is made a CSV file is returned that contains a list of the same length of (email,link) that we can stick in any email body we want for sending out to people.

If this is correct, then that should work great for us.

(Sam Saffron) #3

Yes, exactly, @techAPJ will free up to work on this in the next week or so.

(Sam Saffron) #4

Extended Spec, email-less tokens. That means that we need an endpoint to generate these.

Email-less tokens get associated on signup, this is the flow

  1. You generate a token [X] which may also confer rights like automatically adding a user to a group
  2. On redemption the redemption link provides an email and optional user / username.

So, we generate the unique one use tokens and the third party fills the blanks, for example:

GUIDs can only be redeemed once, we have no idea what the email is until they finally accept it.

(Arpit Jalan) #5

Implemented via:


Also wrote a how-to for this:


The URL for disposable invite will be:

Notice the extra redeem in URL.

(Steve Baer) #6

Great! @sam and @codinghorror we really want to test this as soon as possible. Would it be possible to upgrade our discourse instance with this new feature?

(Sam Saffron) #7

@techAPJ is working on your part of the spec next, should have it done in the next 2 days or so.

(Steve Baer) #8

Hmm… okay. I’m confused; it seems like the disposable invite tokens feature pretty much solves what we were looking to do.

(Sam Saffron) #9

You can use that if you wish, but you will need to tack “emails and username” to every invite you generate, we are building a second part to this that allows you to associate the email with the invite.

Up to you, you can use the disposable tokens if you wish .

(Steve Baer) #10

I would love to try if possible. We are trying to test this out with an event that is coming up this fall and we want to try and send out emails as soon as possible. I’m assuming our current discourse server does not have the disposable invite feature yet since it was just pushed a few hours ago. Would it be possible to upgrade our server so we can try this?

Thanks; and sorry for being a pain.

(Sam Saffron) #11

I just hit the deploy button so you should have the feature, feel free to try it out, follow @techAPJ’s howto.

(Steve Baer) #12

I just attempted to run the disposable_invite_tokens.rb example with my settings (site, username, apikey) and get the following error

C:\dev\github\discourse\discourse_api\examples>ruby disposable_invite_tokens.rb

disposable_invite_tokens.rb:12:in <main>': undefined methodbody’ for #<Hash:0
x2846be0> (NoMethodError)

I would normally link this to my personal ignorance about ruby, but it looks like much of the script ran and a “NoMethodError” may be signifying that no method on the server exists (wild ass guessing now.) Can you tell if I’m running the script incorrectly or if our discourse server has not been fully deployed with these changes yet?

(Arpit Jalan) #13

Weird. It seems like your Discourse instance is not returning array of tokens.

If you can PM me the API key and Admin username of your Discourse instance, I can help you with this.

(Jeff Atwood) #14