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-keyheader on every request. Go to Manage API keys to create a key and token.Account, organization, and project IDs: Send
accountIdentifieras a query parameter on every request. AddorgIdentifierandprojectIdentifierfor repositories in an organization or project. Go to 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:
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 withGET /repos/{repo_identifier}/branchesandGET /repos/{repo_identifier}/commits. Go to 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 withPOST /repos/{repo_identifier}/pullreq/{pullreq_number}/reviews, and merge it withPOST /repos/{repo_identifier}/pullreq/{pullreq_number}/merge. Go to 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}/rulesand add one withPOST /repos/{repo_identifier}/rules. Go to Enable 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 /labelsand create one withPOST /labels. Go to 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}/webhooksand add one withPOST /repos/{repo_identifier}/webhooks. Go to Configure Webhooks to configure webhooks.
Last updated
Was this helpful?