How do I find deleted posts via API?

I’m trying to use the API to keep a list of recent posts. This works well using posts.json.

But the problem I’m having is that deleted posts do not show in posts.json. And there doesn’t appear to be a posts_deleted.json or anything similar.

So how can I find all the deleted posts via the API? This seems like a simple thing, but I can’t figure it out. Am I missing something?

I don’t think this is possible. Maybe if you post some details about why you are trying to find deleted posts via the API someone will have ideas about alternate ways of approaching the problem you’re trying to solve.

One possibility is that you could configure a Post Event webhook to point to an external service. That webhook will be fired when a post is created, edited, deleted, or recovered. Possibly that webhook would give you the information you need.

1 Like

I use the API to store posts in my database so I don’t have to call the API every time I want to display data for every user. This also allows me to connect the data fully to all of my tables, add it to views, etc.

I then can show information about posts on my website, outside of discourse.

But since there’s apparently no way to find out when posts are deleted, I end up showing some deleted posts and people don’t understand why the links aren’t working right.

I don’t understand why there’s no way to find deleted posts? It seems a very obvious tool. There’s even a field in posts.json for “user deleted”, but this field apparently can never be True, because the posts.json will never show a deleted post. So either that field shouldn’t exist or the posts.json should be showing deleted posts.

1 Like

This is a great approach!

I think that pointing a Post Event webhook to your application would work for this. When a post is deleted, the webhook’s X-Discourse-Event will be set to post_destroyed. You could save the post ids for destroyed posts on your application and exclude those posts when displaying Discourse content on your site.

2 Likes