# APIでサイト全体のユーザーの全投稿を削除？

**URL:** <https://meta.discourse.org/t/delete-all-posts-by-a-user-on-entire-site-with-api/302332>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [2024 年 4 月 4 日午前 2:53 UTC](https://meta.discourse.org/t/delete-all-posts-by-a-user-on-entire-site-with-api/302332 "2024-04-04T02:53:10Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2024 年 4 月 4 日午前 4:26 UTC](https://meta.discourse.org/t/delete-all-posts-by-a-user-on-entire-site-with-api/302332/2 "2024-04-04T04:26:07Z")

</div>

「Lola、APIを使用してユーザーのDiscourseの投稿をすべて削除するにはどうすればよいですか？」

> [@「Lola the Coding Assistant Bot」](#):
>
> API経由でユーザーのDiscourseの投稿をすべて削除するには、次の手順に従います。
> 
> 1. **ユーザーの投稿を取得** : ユーザーのすべての投稿のリストを取得します。
> 2. **各投稿を削除** : リストを反復処理し、各投稿を削除します。
> 
> ### 1. ユーザーの投稿を取得
> 
> **エンドポイント** : `GET /posts.json`  
> **パラメータ** : `username`: ユーザーのユーザー名。
> 
> ```plaintext
> curl -X GET "http://yourdiscourse.example.com/posts.json?username=targetUser" \
> -H "Api-Key: your_api_key" \
> -H "Api-Username: your_admin_username"
> 
> ```
> 
> ### 2. 各投稿を削除
> 
> **エンドポイント** : `DELETE /posts/{id}.json`
> 
> ステップ1から各投稿IDをループし、次のコマンドを使用します。
> 
> ```plaintext
> curl -X DELETE "http://yourdiscourse.example.com/posts/{post_id}.json" \
> -H "Api-Key: your_api_key" \
> -H "Api-Username: your_admin_username"
> 
> ```
> 
> `{post_id}`を実際の投稿IDに置き換えてください。
> 
> **注意** : 必要な権限があることを確認し、一括削除のインプリケーションを認識してください。この操作は元に戻すことはできません。

---

_[View the full topic](https://meta.discourse.org/t/delete-all-posts-by-a-user-on-entire-site-with-api/302332)._
