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.
9 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.I should have been more clear - I meant how do you edit an existing post.
According to the code above if you send a
PUTrequest 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 theEditPoststruct.Wait - never mind. It's just creating new posts and not editing the existing one...
make sure you're sending a
PUTrequest and not aPOSTrequest. a PUT will edit, where-as a POST will create.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....
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.Looking at the contract / struct. It looks like you should only need the
post_idand theauthtoken. I don't even see acommunity_idparameter.Okay, that did it - just like you said: use a requests.put with those parameters and that's all it needs. Thanks!