# Invite token bulk email API sample

**URL:** https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186
**Category:** Feature
**Tags:** rfc, spec
**Created:** [July 3, 2014, 11:57pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186 "2014-07-03T23:57:45Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 3, 2014, 11:57pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/1 "2014-07-03T23:57:45Z")

</div>

@codinghorror started a sister topic on general [improvements to the invite system](https://meta.discourse.org/t/improve-topic-invites/17184).

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

###Example

```bash
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.

Note:

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

Feedback @stevebaer @bobmcneel ?

---

<div class="post-metadata">

### Author: ![stevebaer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevebaer/32/105244_2.png) [@stevebaer](https://meta.discourse.org/u/stevebaer)
#### Post date: [July 7, 2014, 9:49pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/2 "2014-07-07T21:49:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 7, 2014, 9:51pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/3 "2014-07-07T21:51:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 10, 2014, 5:31am UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/4 "2014-07-10T05:31:25Z")

</div>

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 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:

`https://meta.discourse.org/invites/GUID?username=bob&email=bob@bob.com&name=Something`

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

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [July 14, 2014, 4:47pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/5 "2014-07-14T16:47:38Z")

</div>

> [@sam](#):
>
> email-less tokens

Implemented via:

[https://github.com/discourse/discourse/pull/2538](https://github.com/discourse/discourse/pull/2538)

and

[https://github.com/discourse/discourse\_api/pull/27](https://github.com/discourse/discourse_api/pull/27)

Also wrote a how-to for this:

> [@Generating lots of Invite Tokens](https://meta.discourse.org/t/generating-disposable-invite-tokens/17563):
>
> warning This plugin is deprecated in favour of our core invite system. Summary: Generate multiple invite tokens link GitHub: [https://github.com/discourse/discourse-invite-tokens](https://github.com/discourse/discourse-invite-tokens)arrow_right Install: Follow the [plugin installation guide](https://meta.discourse.org/t/install-a-plugin/19157). Configuration Enable plugin After installing plugin enable site setting invite tokens enabled. Clone Discourse API Gem If you already have Git and Ruby installed on your system, you can install Discourse API by running following command from consol…

_Note:_

The URL for disposable invite will be:

`https://meta.discourse.org/invites/redeem/GUID?username=bob&email=bob@bob.com&name=Something`

Notice the extra `redeem` in URL.

---

<div class="post-metadata">

### Author: ![stevebaer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevebaer/32/105244_2.png) [@stevebaer](https://meta.discourse.org/u/stevebaer)
#### Post date: [July 14, 2014, 9:35pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/6 "2014-07-14T21:35:54Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 14, 2014, 9:36pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/7 "2014-07-14T21:36:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![stevebaer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevebaer/32/105244_2.png) [@stevebaer](https://meta.discourse.org/u/stevebaer)
#### Post date: [July 14, 2014, 9:53pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/8 "2014-07-14T21:53:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 14, 2014, 10:31pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/9 "2014-07-14T22:31:59Z")

</div>

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 .

---

<div class="post-metadata">

### Author: ![stevebaer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevebaer/32/105244_2.png) [@stevebaer](https://meta.discourse.org/u/stevebaer)
#### Post date: [July 14, 2014, 10:58pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/10 "2014-07-14T22:58:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 14, 2014, 10:59pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/11 "2014-07-14T22:59:25Z")

</div>

> [@stevebaer](#):
>
> 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?

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

---

<div class="post-metadata">

### Author: ![stevebaer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevebaer/32/105244_2.png) [@stevebaer](https://meta.discourse.org/u/stevebaer)
#### Post date: [July 15, 2014, 5:55pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/12 "2014-07-15T17:55:10Z")

</div>

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 method `body’ 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?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [July 15, 2014, 6:46pm UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/13 "2014-07-15T18:46:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [September 8, 2014, 3:15am UTC](https://meta.discourse.org/t/invite-token-bulk-email-api-sample/17186/14 "2014-09-08T03:15:23Z")

</div>


