# Discoursehacking – adding Badges to Users, in bulk, in Discourse

**URL:** https://bawmedical.co.uk/t/discoursehacking-adding-badges-to-users-in-bulk-in-discourse/52
**Category:** blog
**Tags:** discourse
**Created:** [20 July 2015 23:00 UTC](https://bawmedical.co.uk/t/discoursehacking-adding-badges-to-users-in-bulk-in-discourse/52 "2015-07-20T23:00:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![marcusbaw](https://bawmedical.co.uk/user_avatar/bawmedical.co.uk/marcusbaw/32/938_2.png) [@marcusbaw](https://bawmedical.co.uk/u/marcusbaw)
#### Post date: [20 July 2015 23:00 UTC](https://bawmedical.co.uk/t/discoursehacking-adding-badges-to-users-in-bulk-in-discourse/52/1 "2015-07-20T23:00:00Z")

</div>

At the time of writing, there’s no Admin UI for granting badges in bulk in Discourse. So we have to do it the Old Navy Way, on the Rails console…

```auto
emails = [array containing all the email addresses of attendees]

# initialize blank array for User objects
userlist = [] 

# pulls only Users where the email matches the one they used for
# Summer Sschool registration without causing errors
emails.each { |e| userlist << User.try(:where, email: e) }
# the use of try avoids errors when no match is found

userlist.reject!(:&empty)
# get rid of any non-matches which are an empty entry in the array
userlist.flatten! # flatten the array by one level

# BadgeGranter requires the Badge object and the User object
# to be passed in as parameters
# In our case we were assigning the Badge with the id number 108
userlist.each {|u| BadgeGranter.grant ( Badge.find(108), u ) }

```

Done!

---

<div class="post-metadata">

### Author: ![marcusbaw](https://bawmedical.co.uk/user_avatar/bawmedical.co.uk/marcusbaw/32/938_2.png) [@marcusbaw](https://bawmedical.co.uk/u/marcusbaw)
#### Post date: [20 January 2020 16:08 UTC](https://bawmedical.co.uk/t/discoursehacking-adding-badges-to-users-in-bulk-in-discourse/52/2 "2020-01-20T16:08:50Z")

</div>

> **[Badge Granting in bulk or for a group of users](https://meta.discourse.org/t/badge-granting-in-bulk-or-for-a-group-of-users/36782)**
>
> So far as I can see there is no facility for granting Badges in bulk except for via the SQL query in the Badge Edit / New Badge page at /admin/badges/ In my Discourse instances we award Badges to people for accolades or for attendance at certain...
