I am trying to import an repository from another repo,
From Microsoft Documentation I found the API endpoint should be like:
Trying to call the API from Postman
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/importRequests?api-version=6.0-preview.1
Request Params
{
"parameters": {
"deleteServiceEndpointAfterImportIsDone": true,
"gitSource": {
"overwrite": false,
"url": "https://{organisation}@dev.azure.com/{organization}/{project}/_git/{repoName}"
},
"tfvcSource": null
}
}
Source - https://learn.microsoft.com/en-us/rest/api/azure/devops/git/import-requests/create?view=azure-devops-rest-6.0
Passing Authorization in the header by converting PAT like this
"Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", pat)));
Via API
ImportRequest importrequest = new ImportRequest()
{
Parameters = new Parameters()
{
DeleteServiceEndpointAfterImportIsDone = true,
GitSource = new GitSource()
{
Overwrite = true,
Url = "https://{organisation}@dev.azure.com/{organization}/{project}/_git/{repoName}",
},
TfvcSource = null,
ServiceEndpointId = "",
},
};
var clientImportRepo = new RestClient($"{devopsURL}{project.id}/_apis/git/repositories/{reponame}/importRequests?api-version=6.0-preview.1");
var createImportProjects = new RestRequest();
createImportProjects.Method = Method.Post;
createImportProjects.AddJsonBody(importrequest);
createImportProjects.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", pat))));
var responseImportepo = await clientImportRepo.ExecuteAsync(createImportProjects);
I am not able to import repository. Please help me on this
Note,
PAT is having full access.
Both the repos are of Private type.
Target Repo is empty.
Able to import from Azure DevOps Portal, But i need to achieve this from API Code.