Search code examples
c#tfsazure-devopstfs-sdkazure-devops-rest-api

Unable to link changeset to work item with TFS API


I want to create a work item and link a changeset to him in C# with .NET client libraries for Azure DevOps Services (and TFS) (the new API).

I successed to create a work item, but if I try also to link a changeset I got an error.

My code:

// After add title etc.
json.Add(
        new JsonPatchOperation()
        {
             Operation = Operation.Add,
             Path = "/relations/-",
             Value = new
             {
                 rel = "ArtifactLink",
                 url = {changesetUrl},
                 attributes = new
                 {
                      name = "Fixed in Changeset"
                 }
             }
       });

// then I create the work item with CreateWorkItemAsync(json, teamProject, "Task")

The exception:

Invalid Resource Link Target: 'http//tfsServer:8080/tfs/collection/_apis/tfvc/changesets/{changesetID}'

What am I doing wrong?


Solution

  • Ok, I managed to figure out where the problem was.

    In the url = {changesetUrl}, I passed in the variable the changeset url('http//tfsServer:8080/tfs/collection/_apis/tfvc/changesets/{changesetID}), this url is not the correct url for this api call.

    The correct url is: vstfs:///VersionControl/Changeset/{changesetID}.

    After I changed the url it worked and the work item created with the link.