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

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?

1 Like

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:

3 Likes

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:

1 Like