# Log out all users via API

**URL:** https://meta.discourse.org/t/log-out-all-users-via-api/75851
**Category:** Feature
**Created:** [December 11, 2017, 11:25pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851 "2017-12-11T23:25:55Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [December 12, 2017, 8:54am UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/5 "2017-12-12T08:54:19Z")

</div>

I’ve documented Rails code that (in addition to doing other things) logs out all users and sends them the usual notification that there were logged out here, in case this helps you:

> [@Re-purposing a Discourse installation for a yearly event](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670/17):
>
> Another year has passed, and we followed the same procedure. This time, we used actual Ruby scripts instead of my crazy API-based approach – maybe this is useful to someone else: Log out and deactivate (almost) all users: protected\_users = ["system", "codinghorror"] # do not process these users # get all users that should be logged out affected\_users = User.all.select { |u| !(protected\_users.include? u.username) } affected\_users.each { |u| u.admin = false u.moderator = false …

---

_[View the full topic](https://meta.discourse.org/t/log-out-all-users-via-api/75851)._
