> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/api-reference/software-delivery-agent-apis/code-repository.md).

# Code Repository

Manage repositories, pull requests, branch rules, labels, and webhooks with the Harness Code Repository API.

The Code Repository API manages Git repositories hosted in Harness Code Repository, and the pull requests, rules, and webhooks around them.

## Request basics

* **API key token**: Send it in the `x-api-key` header on every request. Go to [Manage API keys](https://developer.harness.io/harness-platform/use-harness-platform/automation/api/add-and-manage-api-keys) to create a key and token.
* **Account, organization, and project IDs**: Send `accountIdentifier` as a query parameter on every request. Add `orgIdentifier` and `projectIdentifier` for repositories in an organization or project. Go to [Organizations and projects](https://developer.harness.io/harness-platform/use-harness-platform/organizations-and-projects) to find these identifiers.
* **Base URL**: Send requests to `https://app.harness.io/gateway/code/api/v1`, followed by the endpoint path.

## Example request

List the repositories in a project:

```bash
curl "https://app.harness.io/gateway/code/api/v1/repos?accountIdentifier=ACCOUNT_ID&orgIdentifier=ORG_ID&projectIdentifier=PROJECT_ID" \
  -H "x-api-key: $HARNESS_API_KEY"
```

Replace `ACCOUNT_ID`, `ORG_ID`, and `PROJECT_ID` with your own values, and set `HARNESS_API_KEY` to your API key token.

## Find an endpoint

Endpoint paths are relative to the base URL.

* **Repositories**: Git repositories hosted in Harness, including branches, tags, commits, and file content. List repositories with `GET /repos`, then branches and commits with `GET /repos/{repo_identifier}/branches` and `GET /repos/{repo_identifier}/commits`. Go to [Manage Repositories](https://developer.harness.io/code-repository/use-harness-code/manage-repositories) to create or import a repository.
* **Pull requests**: Proposed changes from one branch to another, with reviews, comments, and merge actions. List pull requests with `GET /pullreq`, review one with `POST /repos/{repo_identifier}/pullreq/{pullreq_number}/reviews`, and merge it with `POST /repos/{repo_identifier}/pullreq/{pullreq_number}/merge`. Go to [Pull Requests](https://developer.harness.io/code-repository/use-harness-code/pull-requests) to work with pull requests.
* **Rules**: Branch and tag protection, such as required reviews or blocked force pushes. List a repository's rules with `GET /repos/{repo_identifier}/rules` and add one with `POST /repos/{repo_identifier}/rules`. Go to [Enable Rules](https://developer.harness.io/code-repository/use-harness-code/manage-repositories/rules) to enable rules.
* **Status checks**: Results that pipelines or external tools report against a commit, which rules can require before merge. Read the checks on a commit with `GET /repos/{repo_identifier}/checks/commits/{commit_sha}`.
* **Labels**: Tags you add to pull requests to sort and filter them. List labels with `GET /labels` and create one with `POST /labels`. Go to [Labels](https://developer.harness.io/code-repository/use-harness-code/collaborate-and-develop/labels) to create labels.
* **Webhooks**: Calls Harness sends to another system when something happens in a repository. List a repository's webhooks with `GET /repos/{repo_identifier}/webhooks` and add one with `POST /repos/{repo_identifier}/webhooks`. Go to [Configure Webhooks](https://developer.harness.io/code-repository/use-harness-code/manage-repositories/webhooks) to configure webhooks.
