# generate\_invite\_link API endpoint throws 500 if invite already redeemed

**URL:** https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146
**Category:** Bug
**Created:** [9월 11, 2015, 10:55오후 UTC](https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146 "2015-09-11T22:55:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![grschafer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grschafer/32/108419_2.png) [@grschafer](https://meta.discourse.org/u/grschafer)
#### Post date: [9월 11, 2015, 10:55오후 UTC](https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146/1 "2015-09-11T22:55:19Z")

</div>

The following error occurs

```plaintext
NoMethodError (undefined method `invite_key' for nil:NilClass)
/var/www/discourse/app/models/invite.rb:82:in `generate_invite_link'

```

on this line: [discourse/app/models/invite.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/invite.rb#L82)

It happens when trying to generate a link for a user that has already been invited. Perhaps it should return a 422, [as inviting by email does](https://github.com/discourse/discourse/blob/master/app/controllers/invites_controller.rb#L47), instead?

I’m trying to call these API endpoints from another application, and would like to differentiate between “already invited” and “server error”. The discourse frontend handles it pretty well though:

* * *

 ![](https://global.discourse-cdn.com/meta/original/3X/0/0/00b461163b2c3e8f5f94d18a11d22901ad1d4190.png)

* * *

Pinging @techAPJ based on involvement in [Copy Invite Link 🔗](https://meta.discourse.org/t/copy-invite-link-link/32648)

Thanks for discourse being awesome!

---

<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: [9월 11, 2015, 11:24오후 UTC](https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146/2 "2015-09-11T23:24:19Z")

</div>

Hmm good point perhaps @techapj can improve the return codes here for API usage?

---

<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: [9월 16, 2015, 12:09오후 UTC](https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146/3 "2015-09-16T12:09:41Z")

</div>

Fixed via:

[https://github.com/discourse/discourse/commit/f2c1dbaa6835b6def784a5dad6bb09a7b62b8751](https://github.com/discourse/discourse/commit/f2c1dbaa6835b6def784a5dad6bb09a7b62b8751)

---

<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: [9월 16, 2015, 12:09오후 UTC](https://meta.discourse.org/t/generate-invite-link-api-endpoint-throws-500-if-invite-already-redeemed/33146/4 "2015-09-16T12:09:46Z")

</div>


