# Using the API, can't PUT to topic unless slug is on the URL

**URL:** https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545
**Category:** Feature
**Tags:** pr-welcome
**Created:** [9월 23, 2016, 2:53오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545 "2016-09-23T14:53:21Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [9월 23, 2016, 2:53오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/1 "2016-09-23T14:53:21Z")

</div>

Found this out while writing a request to change the tags on a topic.

Basically, this doesn’t work:

```plaintext
PUT /t/123.json?api_username=...&api_key=...

{
  tags: ['a']
}

```

The server responds with:

```plaintext
403
{
  "errors": [
    "You are not permitted to view the requested resource."
  ],
  "error_type": "invalid_access"
}

```

However, if you put the topic slug on the URL, everything works fine (i.e. `PUT /t/why-arent-there-better-animals/123.json?api_username=...&api_key=...`)

This is inconsistent with the other topic API methods which do _not_ require a slug, and differs from the behavior described in the API documentation: [Discourse REST API Documentation](https://meta.discourse.org/t/discourse-api-documentation/22706)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [9월 24, 2016, 12:09오전 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/2 "2016-09-24T00:09:43Z")

</div>

Does it work if you use a wrong slug?

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [9월 27, 2016, 10:06오전 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/3 "2016-09-27T10:06:52Z")

</div>

I’m pretty sure the answer is _No_, based on previous testing, but I don’t have the time to reproduce this right now.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [9월 27, 2016, 12:21오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/4 "2016-09-27T12:21:55Z")

</div>

Yes it appears that you need the slug to be present to make the PUT request on topics and you can use the wrong slug and it will work fine.

See my demo:

 ![](https://global.discourse-cdn.com/meta/original/3X/5/f/5f8c287e23bb4a5b597bb511de23fe99cbcc9089.gif)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [9월 27, 2016, 4:47오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/5 "2016-09-27T16:47:53Z")

</div>

Okay, so just hardcode a slug of a single dash 🙂

---

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [9월 27, 2016, 5:01오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/6 "2016-09-27T17:01:49Z")

</div>

That’s fine for a workaround but it’s still a bug.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [9월 27, 2016, 7:49오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/7 "2016-09-27T19:49:49Z")

</div>

How is that a bug and not required syntax?

To work as expected routing depends on URLs to be in a certain format.

So this seems more like “change the way the API works with improper URLs” feature request than a bug to me.

---

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [9월 27, 2016, 8:08오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/8 "2016-09-27T20:08:41Z")

</div>

Well, none of the other topic API methods require that, so I’d call it a bug.

---

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [9월 27, 2016, 8:10오후 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/9 "2016-09-27T20:10:31Z")

</div>

Put differently, why is it reasonable for `GET /t/:topicId` to work and `DELETE /t/:topicId` to work and `PUT /t/:topicId` to not work?

---

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [9월 28, 2016, 1:54오전 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/10 "2016-09-28T01:54:16Z")

</div>

I edited the original topic to clarify _why_ this is a bug, but I’d like to highlight that the API documentation itself states that this should work:

> [@Discourse REST API Documentation](https://meta.discourse.org/t/discourse-api-documentation/22706):
>
> Discourse API Please view the Discourse API Documentation site for detailed info: [https://docs.discourse.org](https://docs.discourse.org)information_source Authentication API requests must use HTTP header based authentication. Pass your Api-Key and Api-Username as HTTP headers. Authentication via query parameters or request body is not supported (this was removed in April 2020). Please see the example cURL request below. The only API endpoints that continue to support credentials in query parameters are requests to…

I think my previous point is relevant as well.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [9월 28, 2016, 8:45오전 UTC](https://meta.discourse.org/t/using-the-api-cant-put-to-topic-unless-slug-is-on-the-url/50545/11 "2016-09-28T08:45:36Z")

</div>

This does not meet our definition of #Contribute > Bug but I am totally fine for a PR that cleans this up cause it would simplify the API.
