How to delete an annotated tag (git tag) in VSTS API?

Viewed 889

I'm able to successfully create an annotated tag (git tag) with the request below, but I'm not able to programmatically delete it.

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/annotatedtags?api-version=4.1-preview.1

Request:

{
    "name": "wagner-test-3",
    "message": "wagner-test-3",
    "taggedObject": {
        "objectId": "aaaaab6cad84a07b7bd65cf3519142a12f856baa"
    }
}

According to the documentation there is no delete endpoint, so I've tried the delete ref endpoint but no luck so far. It only returns 400 (Invalid Request).

DELETE https://dev.azure.com/{organization}/{project}/_apis/git/favorites/refs/{favoriteId}?api-version=4.1-preview.1

Response:

{
    "count": 1,
    "value": {
        "Message": "The request is invalid."
    }
}

Thanks.

1 Answers

I was able to figure out my own question. The way to delete an annotated tag is to update it with the Refs API. This is not well documented though.

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=4.1

Request:

[
    {
        "name": "refs/tags/wagner-test-3",
        "newObjectId": "0000000000000000000000000000000000000000",
        "oldObjectId": "aaaaab6cad84a07b7bd65cf3519142a12f856baa"
    }
]

Azure DevOps documentation: Refs - Update Refs Creating, updating, or deleting refs(branches).

Related