How to delete a branch through the API?

Hi everyone! I’m searching for a way to delete a branch through the API (REST or Octokit). I need to interact with the branch in a workflow after merging the PR (on the pull request close event), and then want to delete it once I’m done. However the documentation makes no mention of this seemingly obvious requirement, so am I missing something?

I found a solution (which isn’t mentioned in the docs anywhere):

curl -s -X DELETE -u username:${{secrets.GITHUB_TOKEN}} https://api.github.com/repos/${{ github.repository }}/git/refs/heads/${{ github.head_ref }}