Possible to change a topic's timestamp?

I’d like to change a topic’s time stamp, found this API
https://docs.discourse.org/#tag/Topics/operation/updateTopicTimestamp

while, it got an error with “Bad CSRF”, could someone give a hint ? thanks

import requests

# incorrect headers
headers = {
    "Authorization": f"Apikey {api_key}",
    "User-Agent": api_username
}

# correct
headers = {"Content-Type": "application/json; charset=utf-8", "Api-Key": api_key, "Api-Username": api_username }

# Modify the post date
created_at = "1701417600"
update_data = {"timestamp": created_at}
response = requests.put(f"https://www.mysite.com/t/6532/change-timestamp.json", json=update_data, headers=headers)

print(response.status_code)   # 403
print(response.text)     # '["BAD CSRF"]'
print(response.json())   # ['BAD CSRF']

Those aren’t the right headers:

Once you have your API Key you can pass it in along with your API Username as an HTTP header like this:

curl -X GET "http://127.0.0.1:3000/admin/users/list/active.json" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: system"

and this is how POST requests will look:

curl -X POST "http://127.0.0.1:3000/categories" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: system" \
-F "name=89853c20-4409-e91a-a8ea-f6cdff96aaaa" \
-F "color=49d9e9" \
-F "text_color=f0fcfd"
2 Likes

thanks @Firepup650
my bad, yes, that is incorrect headers, posted the correct one above, it works.

1 Like

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