I started to love the Python black formatter and I want all my code on Stack Overflow to be formatted like that. So I wanted to go over the answers and apply black / blacken-docs, check if anything went wrong and apply the change if it looks fine. I would execute that on my machine.

I'm currently struggling with the last step: Editing my answer / uploading the edited answer. How can I do that?

(In case you're interested: The current work in progress)


You'll need an API token with write access, which is only available for registered Stack Apps. You might be able to use this very question to obtain a key for your application, or post another question.

The /answers/{id}/edit method is the one you're looking for. It's a POST call; the id parameter needs to be in the URL, the other ones as application/x-www-form-urlencoded content in the request body. body is the new Markdown of the post; comment is the edit summary.

  • Does that mean it is impossible to run it locally, as I need an application domain? Jun 7 '20 at 19:30
  • You can absolutely run it locally if you only need a token for yourself. If I'm not mistaken, you can just use localhost as the redirect URI.
    – Glorfindel
    Jun 7 '20 at 20:19
  • @MartinThoma I usually do it with cURL, I've written about it in more detail here.
    – Glorfindel
    Jun 8 '20 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .