Thank you, will try this out sometime today! So, can that rake stuff be done as a normal user? I would like this all to be done as a normal user who isn’t staff.
This.
When I ran the python script below:
import requests
# Configuration
discourse_base_url = 'https://forums.mysite.me/'
api_key = 'eb4065d1dergrgh45h45h54h45reg4g70cbeb274bf7f87'
api_username = 'username'
target_username = 'targetusername'
# Headers for API requests
headers = {
'eb4065d1dergrgh45h45h54h45reg4g70cbeb274bf7f87': api_key,
'B': api_username
}
def get_user_posts(username):
"""Fetch posts by a specific user."""
posts = []
url = f'{discourse_base_url}/posts.json?username={username}'
response = requests.get(url, headers=headers)
if response.status_code == 200:
posts_data = response.json()
posts = posts_data.get('latest_posts', [])
return posts
def delete_post(post_id):
"""Delete a specific post."""
url = f'{discourse_base_url}/posts/{post_id}.json'
response = requests.delete(url, headers=headers)
return response.status_code == 200
def main():
# Fetch user posts
posts = get_user_posts(target_username)
# Delete each post
for post in posts:
post_id = post.get('id')
if delete_post(post_id):
print(f'Successfully deleted post {post_id}')
else:
print(f'Failed to delete post {post_id}')
if __name__ == '__main__':
main()
On my terminal/console, I get:
Failed to delete post 73
Failed to delete post 71
Failed to delete post 69
Failed to delete post 60
Failed to delete post 47
I tried 2 API keys I made. One with only me who can use it and one will all users. Both times, used the Global option. Same result.