Visual Studio Team Services:使用RestSharp和JSON.NET获取所有工作项

时间:2016-05-30 08:32:08

标签: json.net azure-devops restsharp azure-devops-rest-api

我正在尝试从Visual Studio Team Services获取所有工作项(是Visual Studio Online)。我已经能够从我的应用程序创建它们,但是找到了所有这些问题。我一直在尝试使用wiql,但我似乎没有让它工作。任何帮助或提示都是相关的。

我的代码:

  var Client = new RestClient("https://myvso.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.0");
        Client.Authenticator = new HttpBasicAuthenticator(username, password);

        IRestRequest request = new RestRequest(Method.POST);
        request.AddHeader("Content-Type", "application/json");
        request.RequestFormat = DataFormat.Json;


        var query = JsonConvert.SerializeObject(new QueryModel() {query = "Select [System.Id] From WorkItems" });

        request.AddJsonBody(query);
        var response = Client.Execute(request);

我不断得到的错误是:

"{\"count\":1,\"value\":{\"Message\":\"Error converting value \\\"{\\\"query\\\":\\\"Select [System.Id], From WorkItems\\\"}\\\" to type 'Microsoft.TeamFoundation.WorkItemTracking.Web.Models.Wiql'. Path '', line 1, position 52.\\r\\n\"}}"

有人可以给我一个关于我的查询有什么问题的提示吗?

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

卸下:

evil-mode

更新

var query = JsonConvert.SerializeObject(new QueryModel() {query = "Select [System.Id] From WorkItems" });