Using Python 3.8 via Discourse API, I was able to retrieve a topic’s tags through the following code:
topic_url = forum_url + f'/t/{topic_id}.json'
topic_obj = requests.get(topic_url, headers=headers).json()
topic_tags = list(topic_obj.get('tags'))
My headers are (API Username has admin rights):
headers = {
'Content-Type': 'application/json',
'Api-Key': api_key,
'Api-Username': api_username
}
However, I cannot update the tags using the same headers:
update_url = forum_url + f'/t/-/{topic_id}.json'
payload = {'tags':['bmw', 'nd', 'ak', 'ca']}
r = requests.put(
update_url,
params=payload,
headers=headers
)
Response:
<Response [500]>
{'status': 500, 'error': 'Internal Server Error'}
I was able to use the same requests method, headers, API credential, and URL to update a topic’s title. I am scratching my head over why my access is denied when updating a topic’s tags. Any pointer would be appreciated! Thanks!