Generating lots of Invite Tokens

There was a misunderstanding about what the tokens do. They won’t solve Robert’s issue unfortunately.


Any chance that public invite tokens will become available? I’m imagining that all it would take is

  1. to allow (certain) tokens to be reused
  2. to make discourse accept those tokens without the email part and instead allow users to enter it on the invite-signup page.

@techAPJ @HAWK is correct but as a team you guys are #1

I hope they become available but have no understanding of the complexity,

I do question if a link could be created from a user that might in turn create random tokens when clicked that accomplish,

1, The invite
2, Credit to the poster

BTW I’m thinking we need a return rocket from Mars while you guys are on it :+1:

1 Like

We could also make good use of this if it’s “on the fence” dev wise.

1 Like

@pfaffman Hi Jay, I’m getting the error noted below when attempting to generate tokens. Any tips? Using either my username or my admin email address in the username field on line 13 of disposable_invite_tokens.rb generates the same error. Could it be due to the fact that the domain associated with the email used in the file


differs from my domain name? If so, what are the next steps to getting tokens generated?

Note: Alternatively, could it be because I’m using a recently released gTLD for my domain and there’s some formatting validation going on?

/Users/mmm/discourse_api/lib/discourse_api/client.rb:149:in `handle_error': {"errors"=>["Email is invalid"], "error_type"=>"record_invalid"} (DiscourseApi::UnprocessableEntity)
from /Users/mmm/discourse_api/lib/discourse_api/client.rb:136:in `request'
from /Users/mmm/discourse_api/lib/discourse_api/client.rb:87:in `post'
from /Users/mmm/discourse_api/lib/discourse_api/api/invite.rb:14:in `disposable_tokens'
from disposable_invite_tokens.rb:13:in `<main>'

What is the full domain name?

Hi Jeff, it’s

Oh, **that’s"" why you’re asking me! Sorry I didn’t recognize your username.

It’s not recognized as a URL when you put it here. That seems like a reasonable hypothesis. I’ll try to have a look into the source later today.

Edit: it would make sense if the unrecognized domain were in the email address, but not the site hostname. Have you tried with just one or two addresses?

1 Like

The error that’s in the Rails logs is this:

Processing by DiscourseInviteTokens::InviteTokensController#create_invite_token as JSON
  Parameters: {"quantity"=>"5", "username"=>"pfaffman"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 33ms (Views: 0.2ms | ActiveRecord: 16.1ms)

It looks like the Gem just claims that “unprocessable entity” is “email is invalid”. I don’t think that there is an invalid email anywhere.

1 Like

I’ve been using the “Copy Invite Link” feature to populate a spreadsheet that’s then fed to an email merge. That gets me a completely customized email invitation that comes from my own address, but it’s a pain in the posterior for more than a few invitations at once.

I’ve read about installing Ruby and using the API to generate links. Sadly, it makes my hair hurt.

I’d really, really like to have a “Bulk links from file” option, or perhaps a sub-option of “Bulk invite from file” that generates multiple links. Ideally, the result would be either a CSV file or an HTML table with email address in one column and the corresponding invitation link in another.

I am not against improving the current feature in core, but I did want to dig into this a bit.

Is there any other tech stack you are comfortable, consuming our API is trivial from pretty much any programming language, you can even do these invite link generation thing direct from curl.


Given my background, I should be able to get comfortable with just about anything. For example, I am teaching Python at the moment. However, I’m also working with hundreds* of K-12 teachers, and having to figure out how to assemble the pieces of something new in the midst of all that seems daunting.

The other side of that coin is that I suspect I’m not the only person who would use such a feature often, especially given the length of the current thread. Upon reflection, I’d think that generating multiple links is probably more useful than generating them one at a time.

* It’s really only dozens of teachers at a time, but it seems like hundreds.

I’ve kludged together some Python that will do what I want. In doing so, I’ve discovered an inconsistency and developed an idea for an enhancement that’s probably easy if “bulk links” ever make it into the core product, and that has been very useful to me.

The “bulk invites” option supports category numbers, but the “invite links” API does not.

If bulk links ever makes it onto the core product, I assume that the input will require columns for email address, groups, and category numbers. I’d like to suggest that the fourth column be “reserved” and that everything to the right of the fourth column be propagated unchanged to the output file. I’ve done that with my hack, and use it for things like given name and surname. That saves an Excel VLOOKUP when I get the result. Also, consider accepting and propagating a header line.

In my own hack, the first three columns of input are for email address, group names, and category numbers. The latter is not used; I put it in for compatibility with bulk invites. The fourth column is reserved, and will hold the link in the output. Columns after that are propagated unchanged to the output. The first line of input is assumed to be a header, and is propagated to the output.

Result: The output file is identical to the input with the exception that the invite link has been filled in. In my case, that obviates the need for any post-processing.


Is there any likelihood this functionality can be worked into the admin screen. I can manage console but the other admins would t have a clue. They need simple GUI style processes and this would be so helpful with new user workflow.

1 Like