# How to use the API to set a timer for a topic?

**URL:** <https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494>\
**Category:** Development\
**Created:** [February 21, 2025, 4:18am UTC](https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494 "2025-02-21T04:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

## AI-generated summary

[AstonJ](/t/-/353494/1) is trying to use the Discourse API to set a timer for a topic to close in 30 days. The API documentation shows a request sample with a `category_id` parameter, which seems inconsistent with setting timers. [Arkshine](/t/-/353494/2) suggests following the [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576) guide and notes that the `category_id` parameter is not required, but depends on the `status_type`. [AstonJ](/t/-/353494/3) resolves the issue by using a user with mod permissions, as they were getting an "invalid access" error due to their category setup. The correct parameters for auto-closing a topic in 30 days are also discussed.

<div class="post-metadata">

**Author:** ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)\
**Post date:** [February 21, 2025, 4:18am UTC](https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494/1 "2025-02-21T04:18:46Z")

</div>

Looking here: [Discourse API Docs](https://docs.discourse.org/#tag/Topics/operation/createTopicTimer) the request sample shows:

`https://{url}/t/{id}/timer.json`

```plaintext
{
  "time": "",
  "status_type": "string",
  "based_on_last_post": true,
  "category_id": 0
}

```

But this does not seem consistent with setting timers (why is the category needed?)

What is the correct way to set a timer for an existing topic so that it closes in 30 days?

---

<div class="post-metadata">

**Author:** ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)\
**Post date:** [February 21, 2025, 4:42am UTC](https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494/2 "2025-02-21T04:42:46Z")

</div>

The best way to figure out how the API works is to follow [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576).

Note in the doc, the param is not “required”. It depends on the `status_type`.  
You would need it if you use the `publish_to_category` type.

Auto-close 30 days will pass these params:  
 ![image](https://global.discourse-cdn.com/meta/original/4X/1/8/7/187500fa74e16e88a32abca6c7eefd852344a0ad.png)

And returns this data:

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/7/d/27dfc8645adc529e512fd71a5c05ba2961f2fb27.png)

---

<div class="post-metadata">

**Author:** ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)\
**Post date:** [February 21, 2025, 6:10am UTC](https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494/3 "2025-02-21T06:10:01Z")

</div>

> [@Arkshine](#):
>
> The best way to figure out how the API works is to follow [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576).

Ah I keep forgetting about that 🙈

> [@Arkshine](#):
>
> Note in the doc, the param is not “required”. It depends on the `status_type`.  
> You would need it if you use the `publish_to_category` type.

I kept getting an error about selecting a sub-category, and I remembered that we changed the text for `invalid_access` as we have things set up so most categories that can be posted in are sub-categories (and people kept trying to post in a parent category). So with invalid access I just needed to change to a user with mod permissions… and it works now, thanks! 👍

---

<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:** [March 23, 2025, 6:10am UTC](https://meta.discourse.org/t/how-to-use-the-api-to-set-a-timer-for-a-topic/353494/4 "2025-03-23T06:10:26Z")

</div>

Closed on March 23, 2025, 6:10am UTC

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