Skip to content

Instantly share code, notes, and snippets.

@kelverarruda
Last active March 6, 2024 02:00
Show Gist options
  • Save kelverarruda/cb861ab4e14b3dea141041d1f027c85a to your computer and use it in GitHub Desktop.
Save kelverarruda/cb861ab4e14b3dea141041d1f027c85a to your computer and use it in GitHub Desktop.
How to create repository using REST API Azure DevOps

How to create repository using REST API Azure DevOps

First obtain your Personal Access Token (PAT):

Go to your Azure DevOps organization. Navigate to User settings > Personal access tokens. Generate a new token with the required permissions (Code > Read & Write). Keep the generated token secure as it grants access to your Azure DevOps resources.

image

Important Permission (Personal API Token - PAT)

image image

Sample Request

POST https://dev.azure.com/<organization>/_apis/git/repositories?api-version=7.1-preview.1

Postman Config to Debug (Optional)

image

Body

{
  "name": "AnotherRepository",
  "project": {
    "id": "<project_id>"
  }
}

Sample Response

Status code 201

{
  "id": "5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "name": "AnotherRepository",
  "url": "https://dev.azure.com/<organization>/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "project": {
    "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "name": "Fabrikam-Fiber-Git",
    "url": "https://dev.azure.com/<project_id>/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "state": "wellFormed",
    "revision": 40,
    "visibility": "private",
    "lastUpdateTime": "2023-10-02T15:29:31.72Z"
  },
  "size": 0,
  "remoteUrl": "https://dev.azure.com/<organization>/<project_id>/_git/AnotherRepository",
  "sshUrl": "git@ssh.dev.azure.com:v3/<organization>/<project_id>/AnotherRepository",
  "webUrl": "https://dev.azure.com/<organization>/<project_id>/_git/AnotherRepository",
  "isDisabled": false,
  "isInMaintenance": false
}

More info

https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-7.2&tabs=HTTP#create-a-repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment