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

AI-generated summary

AstonJ 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 suggests following the Reverse engineer the Discourse API guide and notes that the category_id parameter is not required, but depends on the status_type. AstonJ 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.

Looking here: Discourse API Docs the request sample shows:

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

{
  "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?

The best way to figure out how the API works is to follow Reverse engineer the Discourse API.

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

And returns this data:

Ah I keep forgetting about that :see_no_evil:

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! :+1: