# How to programmatically log out lots of users

**URL:** https://meta.discourse.org/t/how-to-programmatically-log-out-lots-of-users/37611
**Category:** Support
**Created:** [January 7, 2016, 9:16pm UTC](https://meta.discourse.org/t/how-to-programmatically-log-out-lots-of-users/37611 "2016-01-07T21:16:47Z")
**Posts on this page:** 1
**Showing post:** 15

<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: [February 3, 2016, 3:32pm UTC](https://meta.discourse.org/t/how-to-programmatically-log-out-lots-of-users/37611/15 "2016-02-03T15:32:47Z")

</div>

As an alternative, here is a bit of JavaScript for node.js that iterates over a list of user ids and logs them out using the API:

```plaintext
var logoutUsers = function (ids, domain, apiKey, delay) {
    var nextIndex = 0;
    var errors = 0;

    var callNextUrl = function () {
        if (nextIndex < ids.length) {
            var id = ids[nextIndex];
            nextIndex++;
            console.log("logging out " + id);
            var req = https.request({
                hostname: domain,
                port: 443,
                path: '/admin/users/' + id + '/log_out?api_key=' + apiKey + '&api_username=system',
                method: 'POST'
            }, function (res) {
                console.log("response: " + res.statusCode);
                res.resume();
                setTimeout(callNextUrl, delay);
            }).on('error', function (e) {
                console.log("Got error: " + e.message);
                errors++;
            });
            req.end();
        } else {
            console.log("Done!");
            console.log("Errors: " + errors);
        }
    };

    callNextUrl();
};

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-programmatically-log-out-lots-of-users/37611)._
