Git import requests

Last Update: 12/5/2016

api-version = 3.0-preview

If you haven't already, look at the information on getting started with these APIs.

Get a list of import requests

GET https://{instance}/DefaultCollection/[{project}]/_apis/git/repositories/{repository}/importRequests?api-version={version}[&includeAbandoned={bool}]
Parameter Type Default Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Team project ID or name.
repository string ID of the repository.
Query
api-version string Version of the API to use.
includeAbandoned bool false If true, include abandoned requests in the result

By repository ID

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests?api-version=3.0-preview

Sample response

Status code: 200
{
  "count": 1,
  "value": [
    {
      "importRequestId": 2,
      "repository": {
        "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "name": "EmptyGitRepo",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "project": {
          "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "name": "Test",
          "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "state": "wellFormed",
          "revision": 7
        },
        "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
      },
      "parameters": {
        "gitSource": {
          "url": "https://github.com/Microsoft/vsts-agent.git"
        }
      },
      "status": "queued",
      "detailedStatus": {
        "currentStep": 1,
        "allSteps": [
          "Processing request",
          "Analyzing repository objects",
          "Storing objects",
          "Storing index file",
          "Updating references",
          "Import completed successfully"
        ]
      },
      "_links": {
        "self": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
        },
        "repository": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
        }
      },
      "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
    }
  ]
}

By repository ID with abandoned requests

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests?includeAbandoned=true&api-version=3.0-preview

Sample response

Status code: 200
{
  "count": 2,
  "value": [
    {
      "importRequestId": 2,
      "repository": {
        "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "name": "EmptyGitRepo",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "project": {
          "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "name": "Test",
          "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "state": "wellFormed",
          "revision": 7
        },
        "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
      },
      "parameters": {
        "gitSource": {
          "url": "https://github.com/Microsoft/vsts-agent.git"
        }
      },
      "status": "queued",
      "detailedStatus": {
        "currentStep": 1,
        "allSteps": [
          "Processing request",
          "Analyzing repository objects",
          "Storing objects",
          "Storing index file",
          "Updating references",
          "Import completed successfully"
        ]
      },
      "_links": {
        "self": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
        },
        "repository": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
        }
      },
      "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
    },
    {
      "importRequestId": 1,
      "repository": {
        "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "name": "EmptyGitRepo",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
        "project": {
          "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "name": "Test",
          "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
          "state": "wellFormed",
          "revision": 7
        },
        "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
      },
      "parameters": {
        "gitSource": {
          "url": "https://github.com/Microsoft/vscode.git"
        }
      },
      "status": "abandoned",
      "detailedStatus": {
        "currentStep": 1,
        "allSteps": [
          "Processing request",
          "Analyzing repository objects",
          "Storing objects",
          "Storing index file",
          "Updating references",
          "Import completed successfully"
        ],
        "errorMessage": "this remote has never connected"
      },
      "_links": {
        "self": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/1"
        },
        "repository": {
          "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
        }
      },
      "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/1"
    }
  ]
}

Get an import request

GET https://{instance}/defaultcollection/[{project}]/_apis/git/repositories/{repository}/importRequests/{importRequestId}?api-version={version}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Team project ID or name.
repository string ID of the repository.
importRequestId int ID of the import request.
Query
api-version string Version of the API to use.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2?api-version=3.0-preview

Sample response

Status code: 200
{
  "importRequestId": 2,
  "repository": {
    "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "name": "EmptyGitRepo",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "project": {
      "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "name": "Test",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "state": "wellFormed",
      "revision": 7
    },
    "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
  },
  "parameters": {
    "gitSource": {
      "url": "https://github.com/Microsoft/vsts-agent.git"
    }
  },
  "status": "queued",
  "detailedStatus": {
    "currentStep": 1,
    "allSteps": [
      "Processing request",
      "Analyzing repository objects",
      "Storing objects",
      "Storing index file",
      "Updating references",
      "Import completed successfully"
    ]
  },
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
    },
    "repository": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
    }
  },
  "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
}

Create a request to import a repository

POST https://{instance}/DefaultCollection/[{project}]/_apis/git/repositories/{repository}/importRequests?api-version={version}
{
  "parameters":
    {
      "gitSource":
        {
          "url": {string}
        },
      "serviceEndpointId": {string},
      "deleteServiceEndpointAfterImportIsDone": {bool}
    }
}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Team project ID or name.
repository string ID of the repository.
Query
api-version string Version of the API to use.
Body
parameters.gitSource.url string Url of the source Git repository to import from
parameters.serviceEndpointId string Service Endpoint ID. Required if source repository is private.
parameters.deleteServiceEndpointAfterImportIsDone bool If true, delete service endpoint after import is done.

Sample request

POST https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests?api-version=3.0-preview
Content-Type: application/json
{
  "parameters": {
    "gitSource": {
      "url": "https://github.com/Microsoft/vsts-agent.git"
    }
  }
}

Sample response

Status code: 201
{
  "importRequestId": 2,
  "repository": {
    "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "name": "EmptyGitRepo",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "project": {
      "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "name": "Test",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "state": "wellFormed",
      "revision": 7
    },
    "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
  },
  "parameters": {
    "gitSource": {
      "url": "https://github.com/Microsoft/vsts-agent.git"
    }
  },
  "status": "queued",
  "detailedStatus": {
    "currentStep": 1,
    "allSteps": [
      "Processing request",
      "Analyzing repository objects",
      "Storing objects",
      "Storing index file",
      "Updating references",
      "Import completed successfully"
    ]
  },
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
    },
    "repository": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
    }
  },
  "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/2"
}

Retry or abandon a failed import request

There can only be one active import request associated with a repository. Marking a failed import request abandoned makes it inactive.

PATCH https://{instance}/defaultcollection/[{project}]/_apis/git/repositories/{repository}/importRequests/{importRequestId}?api-version={version}
{
  "status": {enum}
}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Team project ID or name.
repository string ID of the repository.
importRequestId int ID of the import request.
Query
api-version string Version of the API to use.
Body
status enum { queued, abandoned } "queued" to retry or "abandoned" to abandon a failed request

Sample request

PATCH https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/1?api-version=3.0-preview
Content-Type: application/json
{
  "status": "abandoned"
}

Sample response

Status code: 200
{
  "importRequestId": 1,
  "repository": {
    "id": "0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "name": "EmptyGitRepo",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5",
    "project": {
      "id": "5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "name": "Test",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/5745879a-8531-41c3-9ed3-ae7fc07309ff",
      "state": "wellFormed",
      "revision": 7
    },
    "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/Test/_git/EmptyGitRepo"
  },
  "parameters": {
    "gitSource": {
      "url": "https://github.com/Microsoft/vscode.git"
    }
  },
  "status": "abandoned",
  "detailedStatus": {
    "currentStep": 1,
    "allSteps": [
      "Processing request",
      "Analyzing repository objects",
      "Storing objects",
      "Storing index file",
      "Updating references",
      "Import completed successfully"
    ],
    "errorMessage": "this remote has never connected"
  },
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/1"
    },
    "repository": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5"
    }
  },
  "url": "https://fabrikam-fiber-inc.visualstudio.com/Test/_apis/git/repositories/0eb02d2e-fff9-4990-bd45-2f7503f5aae5/importRequests/1"
}