Talal Yousif
Talal Yousif

Reputation: 1094

Azure Devops GitHttpClient's CreateAnnotatedTagAsync API fails

When calling GitHttpClient.CreateAnnotatedTagAsync, I keep getting "VS30063: You are not authorized to access https://dev.azure.com" even though my credentials are valid.

This is my code:

    var vssConnection = new VssConnection(new Uri("ORG_URI"),  new VssBasicCredential(string.Empty, "PAT"));

    var gitClient = vssConnection.GetClient<GitHttpClient>();

    var tag = new GitAnnotatedTag
    {
        Name = "tagname",
        Message = "A new tag",
        TaggedBy = new GitUserDate
        {
            Name = "Name",
            Email = "Email",
            Date = DateTime.Now,
            ImageUrl = null
        },
        ObjectId = "SHA",
        TaggedObject = new GitObject
        {
            ObjectId = "SHA",
            ObjectType = GitObjectType.Commit
        },
        Url = string.Empty
    };

    var sourceRepo = await gitClient.GetRepositoryAsync("PROJECT", repoName);

    // This call works
    var tags = await gitClient.GetTagRefsAsync(sourceRepo.Id);

    // The tag is printed to the console
    Console.WriteLine(tags.First().Name);

   // This throws "VS30063: You are not authorized to access https://dev.azure.com"
   await gitClient.CreateAnnotatedTagAsync(tag, "PROJECT", sourceRepo.Id);

Upvotes: 0

Views: 370

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40799

There is an issue with your PAT token. I just created a tag using your code and PAT with FULL Access:

enter image description here

Can you create a new token and try again?

Upvotes: 1

Related Questions