# Change default auto-close on all categories

**URL:** https://meta.discourse.org/t/change-default-auto-close-on-all-categories/114841
**Category:** Support
**Created:** [April 12, 2019, 9:29am UTC](https://meta.discourse.org/t/change-default-auto-close-on-all-categories/114841 "2019-04-12T09:29:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wjjjjt](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wjjjjt/32/138195_2.png) [@wjjjjt](https://meta.discourse.org/u/wjjjjt)
#### Post date: [April 12, 2019, 9:29am UTC](https://meta.discourse.org/t/change-default-auto-close-on-all-categories/114841/1 "2019-04-12T09:29:54Z")

</div>

[We](https://community.endlessos.com/)’ve found that our users like to add new comments on very old topics, often only tangentially related to their problem. I would like to set all categories to auto-close topics some time after the last post (7 days – just for the sake of argument!).

I have found [this thread](https://meta.discourse.org/t/apply-auto-close-to-existing-topics/70450) on how to apply a new auto-close configuration to existing topics, but I can’t find any way to adjust the auto-close configuration for all categories. I don’t especially want to do this by hand for two dozen (sub-)categories or so.

Perhaps it’d be safe to `UPDATE categories SET auto_close_hours = 168, auto_close_based_on_last_post = true;` if I had access to the database?

---

<div class="post-metadata">

### Author: ![wjjjjt](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wjjjjt/32/138195_2.png) [@wjjjjt](https://meta.discourse.org/u/wjjjjt)
#### Post date: [April 27, 2019, 12:19pm UTC](https://meta.discourse.org/t/change-default-auto-close-on-all-categories/114841/2 "2019-04-27T12:19:40Z")

</div>

My colleague Nimrod came up with the following script to do this:

```python
#!/usr/bin/env python3
import os
import requests

if __name__ == ' __main__':
    username = os.environ['DISCOURSE_API_USERNAME']
    key = os.environ['DISCOURSE_API_KEY']
    s = requests.session()
    s.headers.update({'Accept': 'application/json'})
    s.params.update({'api_key': key, 'api_username': username})
    base = 'https://community.endlessos.com/'
    update = {'auto_close_hours': '168', 'auto_close_based_on_last_post': True}
    parents = s.get(base + 'categories').json()['category_list']['categories']
    for p in parents:
        p.update(update)
        r = s.put(base + 'categories/' + str(p['id']), params=p)
        assert r.ok
        categories = s.get(base + 'categories', params={'parent_category_id': p['id']}).json()['category_list']['categories']
        for c in categories:
            c.update(update)
            r = s.put(base + 'categories/' + str(c['id']), params=c)
            assert r.ok

```

It seemed to work fine – now that I look at it, if categories can be nested more than one level deep, it will miss third- and subsequent-level categories. On our instance we only have one level of nesting, and I don’t know whether it’s possible to go further in general.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 27, 2019, 12:24pm UTC](https://meta.discourse.org/t/change-default-auto-close-on-all-categories/114841/3 "2019-05-27T12:24:23Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
