VSTS / TFS Error Occurred While Trying to get Work Items With WIQL

拟墨画扇 提交于 2019-12-12 02:35:53

问题


I am using below method to obtain workitem Ids with specific title from my VSTS extension. I am using REST API , Typescript and WIQL .

public getWorkItemsbyQueryFilter(): string[] {               

            try {               

                let query =  "Select [System.Id] From WorkItems Where [System.WorkItemType] = '" + this.workItemType + "' AND [System.Title] contains 'ABC'";
                var ids : string[];           
                var self = this;
                var colURL =  this.collectionURL +this.teamProject +"/_apis/wit/wiql?api-version=1.0"

                var options = {            
                    url: colURL,
                    username: this.username,
                    password: this.password,
                    domain: this.domain,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }, 
                    body :{
                        'query': query
                    }         
                };

                httpntlm.post(options, function(err,res) {

                    if(err) {
                        console.log("Error : +"+ err)
                        deferred.reject(err);
                    }
                    var obj = JSON.parse(res.body);

                    for (var index = 0; index < obj.workItems.length; index++) {
                       ids.push(obj.workItems[index].id);                   
                    }             

                    return ids;
                });       

            } catch (error) {
                console.log("Failed to Get Work Item Ids :"+ error);               
            }
        }

I got below error when I execute this method . As per my web research I couldn't find much to resolve this issue

Unhandled: must start with number, buffer, array or string

Next I have try this request in postman (chrome extension). I am getting new error in same. It seems like something wrong with Json ,but I couldn't figure out what exactly it is. Please be kind enough to show some light.

{"count":1,"value":{"Message":"Error converting value \"query\" to type 'Microsoft.TeamFoundation.WorkItemTracking.Web.Models.Wiql'. Path '', line 1, position 7.\r\n"}}

回答1:


The body value must be the string if you want to use body, for example:

body:`{
       'query': 'Select [System.Id] From WorkItems Where [System.WorkItemType] = "Bug" AND [System.Title] contains "bug"'
      }`



回答2:


Thanks a lot for help me out. I was able to figure it out and fix this issue. I have to use "json" instead of "body" to fix this issue (Please check below code ..However I still get same error in postman . Still trying to figure-out why its giving error).

 var options = {            
                    url: colURL,
                    username: this.username,
                    password: this.password,
                    domain: this.domain,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }, 
                    json :{
                        'query': query
                    }         
                };


来源:https://stackoverflow.com/questions/42856174/vsts-tfs-error-occurred-while-trying-to-get-work-items-with-wiql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!