# 从 API 删除草稿帖子 - 收到 not\_found 错误

**URL:** https://meta.discourse.org/t/delete-draft-post-from-the-api-getting-not-found-error/401220
**Category:** Development
**Tags:** rest-api
**Created:** [2026年四月22日 08:38 UTC](https://meta.discourse.org/t/delete-draft-post-from-the-api-getting-not-found-error/401220 "2026-04-22T08:38:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nitinkg](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@nitinkg](https://meta.discourse.org/u/nitinkg)
#### Post date: [2026年四月22日 08:38 UTC](https://meta.discourse.org/t/delete-draft-post-from-the-api-getting-not-found-error/401220/1 "2026-04-22T08:38:25Z")

</div>

您好，

我尝试通过 API 删除一个草稿：

```plaintext
DELETE /drafts/{draft_key}.json

```

该草稿确实存在（已通过 `GET /drafts.json` 验证），并且我使用了正确的 `draft_key` 和 `sequence`。

### API 请求（Postman / 后端）

```plaintext
DELETE https://<base_url>/drafts/{draft_key}.json

```

**请求头：**

```plaintext
Api-Key: <api_key>
Api-Username: <username>
Content-Type: application/x-www-form-urlencoded / application/json

```

**请求体（两种格式都尝试过）：**

x-www-form-urlencoded：

```plaintext
draft_key=new_topic_xxxxx
sequence=12

```

或原始 JSON：

```plaintext
{
  "draft_key": "new_topic_xxxxx",
  "sequence": 12
}

```

### 响应

```plaintext
{
  "errors": ["The requested URL or resource could not be found."],
  "error_type": "not_found"
}

```

### 从 UI 界面（正常工作）

通过浏览器使用以下方式可以成功删除：

- `DELETE /drafts/{draft_key}.json`

- 表单数据：`draft_key` + `sequence`

- 会话 Cookie + CSRF 令牌

### 问题

是否支持通过 API Key 认证进行草稿删除，与其他 API 一样？如果支持，调用此端点的正确方式是什么？

谢谢。

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年四月22日 10:32 UTC](https://meta.discourse.org/t/delete-draft-post-from-the-api-getting-not-found-error/401220/3 "2026-04-22T10:32:31Z")

</div>

> [@nitinkg](#):
>
> 通过 API 密钥认证是否支持草稿删除，与其他 API 一样？

你试过在查询参数中也传递用户名吗？（即在 URL 末尾添加 `?username=<用户名>`）

看来我们在没有提供 `username` 查询参数时，允许 API 回退到 `Api-Username` 用户名的方式不够一致。

这个问题应该已在以下提交中修复：

> <https://github.com/discourse/discourse/pull/39449>
>
> Admin callers using the API to \`DELETE /drafts/:id.json\` or \`DELETE /review/:id.…json\` received a \`not\_found\` error when the \`username\` param was omitted, even though the resource existed and was owned by the API user (\`Api-Username\`). The destroy actions always called \`fetch\_user\_from\_params\` on the API path, which raises \`Discourse::NotFound\` when neither \`username\` nor \`external\_id\` is provided — forcing callers to redundantly pass \`username=\<self\>\` to delete their own resources.
> 
> Extract the target-user resolution into a shared \`fetch\_target\_user\` helper in \`ApplicationController\` that mirrors the pattern already used by \`topics#set\_notifications\`: for API requests, an admin can target another user via \`username\`/\`external\_id\`; otherwise the action operates on \`current\_user\`. This also aligns API capabilities with the UI — non-admin API callers can now manage their own drafts/reviewables, matching what they can already do via the web.
> 
> Migrated call sites:
> 
> \- \`DraftsController#destroy\` and \`#bulk\_destroy\`
> \- \`ReviewablesController#destroy\`
> \- \`TopicsController#set\_notifications\` (now uses the helper instead of its inline version)
> 
> https://meta.discourse.org/t/401220

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年六月3日 16:09 UTC](https://meta.discourse.org/t/delete-draft-post-from-the-api-getting-not-found-error/401220/4 "2026-06-03T16:09:13Z")

</div>


