# Tag toevoegen via Discourse API mislukt

**URL:** https://meta.discourse.org/t/add-tag-via-discourse-api-failed/200536
**Category:** Development
**Tags:** rest-api
**Created:** [15 augustus 2021 om 23:51 UTC](https://meta.discourse.org/t/add-tag-via-discourse-api-failed/200536 "2021-08-15T23:51:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![littleviolette](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@littleviolette](https://meta.discourse.org/u/littleviolette)
#### Post date: [15 augustus 2021 om 23:51 UTC](https://meta.discourse.org/t/add-tag-via-discourse-api-failed/200536/1 "2021-08-15T23:51:40Z")

</div>

Using Python 3.8 via Discourse API, I was able to retrieve a topic’s tags through the following code:

```plaintext
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):

```plaintext
headers = {
    'Content-Type': 'application/json',
    'Api-Key': api_key,
    'Api-Username': api_username
}

```

However, I cannot update the tags using the same headers:

```plaintext
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:

```plaintext
<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!

---

<div class="post-metadata">

### Author: ![yhmtsai](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@yhmtsai](https://meta.discourse.org/u/yhmtsai)
#### Post date: [19 augustus 2021 om 20:50 UTC](https://meta.discourse.org/t/add-tag-via-discourse-api-failed/200536/2 "2021-08-19T20:50:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [18 september 2021 om 20:51 UTC](https://meta.discourse.org/t/add-tag-via-discourse-api-failed/200536/3 "2021-09-18T20:51:22Z")

</div>

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