Add tag via Discourse API Failed

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!

1 Like

As far as I remember, you need to use tags[] not tags

2 Likes

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