Possible to change a topic's timestamp?

AI-generated summary

Possible to change a topic’s timestamp?

The discussion revolves around updating a topic’s timestamp using the Discourse API. fbpbdmin shared their attempt to use the updateTopicTimestamp API but encountered a “Bad CSRF” error.

Firepup650 pointed out the incorrect headers used in the request, providing examples of correct API key and username headers from the Discourse API documentation.

fbpbdmin thanked Firepup650 and acknowledged the mistake, confirming that the correct headers worked successfully.

I’d like to change a topic’s time stamp, found this API

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"

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