Trying to import a private GitHub repository into Azure DevOps using the REST API:
Unsurprisingly, the documentation doesn't work.
I have a PAT based service endpoint in the DevOps project that has access to the GitHub repository I'm trying to import.
I have the following PowerShell snippet that reproduces the problem
$headers = @{
Authorization = "Bearer ****"
}
$org = '***'
$project = '***'
$targetRepositoryId = '***'
$sourceRepositoryUrl = '***'
$gitHubServiceEndpointId = '***'
irm https://dev.azure.com/$org/$project/_apis/git/repositories/$targetRepositoryId/importRequests?api-version=6.0-preview.1 -Method Post -Headers $headers -ContentType application/json -Body @"
{
"parameters": {
"gitSource": {
"overwrite": false,
"url": "$sourceRepositoryUrl"
},
"serviceEndpointId": "$gitHubServiceEndpointId",
"deleteServiceEndpointAfterImportIsDone": false
}
}
"@
Throws a 400 error (Bad Request) with no additional information.
If I make the GitHub repository public, the exact same API request and the exact same code above works fine.
I am also 100% certain that the service endpoint has access to the repository in question because I have pipelines in Azure DevOps that use this service endpoint to clone said repository from GitHub.