---
title: "Commit an autofix for a code scanning alert"
method: POST
path: "/repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/autofix/commits"
tags: ["code-scanning"]
---

# Commit an autofix for a code scanning alert

`POST /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/autofix/commits`

Commits an autofix for a code scanning alert from the repository's default branch.

If an autofix is committed as a result of this request, then this endpoint will return a 201 Created response.

OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint with private or public repositories, or the `public_repo` scope to use this endpoint with only public repositories.

## Path parameters

- `owner` string, required
- `repo` string, required
- `alert_number` integer, required — The security alert number.

## Request body

- CodeScanningAutofixCommits, nullable — Commit an autofix for a code scanning alert
  - `target_ref` string — The Git reference of target branch for the commit. Branch needs to already exist. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
  - `message` string — Commit message to be used.

## Response `201`

Created

- CodeScanningAutofixCommitsResponse
  - `target_ref` string — The Git reference of target branch for the commit. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
  - `sha` string — SHA of commit with autofix.

## Other responses

- `400` — Bad Request
- `403` — Response if the repository is archived or if GitHub Advanced Security is not enabled for this repository
- `404` — Resource not found
- `422` — Unprocessable Entity
- `503` — Service unavailable

---

[API](https://skmtc.net/github/apis/api-github-com.md) · [All operations](https://skmtc.net/github/apis/api-github-com/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/api-github-com/revisions/a367f7028301/schema)
