How do you edit an existing post via the API?

Documentation is lacking and the API does not return error messages consistently.
https://join-lemmy.org/api/interfaces/EditPost.html
is unhelpful since I'm looking for the URL to hit.
I assumed I'd be able to use

https://lemmy.world/api/v3/post/edit?id=xxxxxx&body=YYYYYEEEAAAHHHHHH  

but it does not work and none of my other guesses about the address have worked either. I don't believe it's an authorization problem.

2 points · 9 comments · view on lemmy.world

9 Comments

marsara9@lemmy.world · 1 pts · 3y (8 replies)

https://github.com/LemmyNet/lemmy/blob/main/src/api_routes_http.rs#L180C13-L180C13

PUT /api/v3/post?... is what you're looking for. But ya, the documentation could be a bit better.

aa45cc00@lemmy.world · 1 pts · 3y (7 replies)

I should have been more clear - I meant how do you edit an existing post.

marsara9@lemmy.world · 1 pts · 3y (6 replies)

According to the code above if you send a PUT request to /api/v3/post?post_id=585124&auth=... it should edit this post you have here.

Just specify the new name, url, body, etc... per the EditPost struct.

aa45cc00@lemmy.world · 1 pts · 3y (2 replies)

Wait - never mind. It's just creating new posts and not editing the existing one...

marsara9@lemmy.world · 1 pts · 3y (1 reply)

make sure you're sending a PUT request and not a POST request. a PUT will edit, where-as a POST will create.

aa45cc00@lemmy.world · 1 pts · 3y

That's almost certainly what's going wrong. I'm working off of a very basic Python interface for the API that I found. Now I need to figure out how to send PUTs with Python's requests library....

aa45cc00@lemmy.world · 1 pts · 3y (2 replies)

Thank you! I got it. I thought all it needed was the id and the body, but you have to supply the name and the community_id as well.

marsara9@lemmy.world · 1 pts · 3y (1 reply)

Looking at the contract / struct. It looks like you should only need the post_id and the auth token. I don't even see a community_id parameter.

aa45cc00@lemmy.world · 1 pts · 3y

Okay, that did it - just like you said: use a requests.put with those parameters and that's all it needs. Thanks!