azure-devops - Azure DevOps REST API Response doesn't contain results when using $top parameter in Wiql request - TagMerge
3Azure DevOps REST API Response doesn't contain results when using $top parameter in Wiql requestAzure DevOps REST API Response doesn't contain results when using $top parameter in Wiql request

Azure DevOps REST API Response doesn't contain results when using $top parameter in Wiql request

Asked 11 months ago
0
3 answers

This issue might be caused by request sql body, try this one:

{
  "query": "SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project ORDER BY [System.ID] ASC"
}

more information see WIQL syntax

Source: link

0

For Azure DevOps Services, instance is dev.azure.com/{organization}, so the pattern looks like this:
VERB https://dev.azure.com/{organization}/_apis[/{area}]/{resource}?api-version={version}
For example, here's how to get a list of team projects in a Azure DevOps Services organization.
curl -u {username}[:{personalaccesstoken}] https://dev.azure.com/{organization}/_apis/projects?api-version=2.0
If you wish to provide the personal access token through an HTTP header, you must first convert it to a Base64 string (the following example shows how to convert to Base64 using C#). (Certain tools like Postman applies a Base64 encoding by default. If you are trying the API via such tools, Base64 encoding of the PAT is not required) The resulting string can then be provided as an HTTP header in the format:
Authorization: Basic BASE64PATSTRING
Here it is in C# using the HttpClient class.
public static async void GetProjects()
{
	try
	{
		var personalaccesstoken = "PAT_FROM_WEBSITE";

		using (HttpClient client = new HttpClient())
		{
			client.DefaultRequestHeaders.Accept.Add(
				new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

			client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
				Convert.ToBase64String(
					System.Text.ASCIIEncoding.ASCII.GetBytes(
						string.Format("{0}:{1}", "", personalaccesstoken))));

			using (HttpResponseMessage response = await client.GetAsync(
						"https://dev.azure.com/{organization}/_apis/projects"))
			{
				response.EnsureSuccessStatusCode();
				string responseBody = await response.Content.ReadAsStringAsync();
				Console.WriteLine(responseBody);
			}
		}
	}
	catch (Exception ex)
	{
		Console.WriteLine(ex.ToString());
	}
}
Here's how to get a list of team projects from TFS using the default port and collection.
curl -u {username}[:{personalaccesstoken}] https://{server}:8080/tfs/DefaultCollection/_apis/projects?api-version=2.0

Source: link

0

Create Connection and Client for worktime Tracking
VssConnection connection = null;
connection = new VssConnection(new Uri("https://" + account + ".visualstudio.com"), new VssBasicCredential(string.Empty, PAT));
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
Create wiql Query
Wiql wiql = new Wiql();
wiql.Query = "SELECT [System.Id] FROM Work Items WHERE [System.TeamProject] = '" + <Team Project name> + "'  AND  [System.WorkItemType] IN GROUP 'Requirement Category' " ;
This query is as follows:
wiql.Query = "SELECT [System.Id], [System.Title], [System.AssignedTo], [System.State], [Microsoft.VSTS.Scheduling.OriginalEstimate], [Microsoft.VSTS.Scheduling.RemainingWork] FROM Work Items WHERE [System.WorkItemType] = 'Task' AND [System.State] = 'Closed' AND [System.TeamProject]='" + <Team Project name> + "'";
The code for fetching and processing data looks as below:
wiql.Query = <wiql query>;
WorkItemQueryResult tasks = witClient.QueryByWiqlAsync(wiql).Result;

if (tasks.WorkItems.Any())
{
    IEnumerable<WorkItemReference> tasksRefs;
    tasksRefs = tasks.WorkItems;
    List<WorkItem> tasksList = witClient.GetWorkItemsAsync(tasksRefs.Select(wir => wir.Id)).Result;
    AllClosedTasks = tasksList.Count;

    foreach (WorkItem task in tasksList)
    {
        int _id = task.Id ?? default(int);
        IEnumerable<string> fields = new List<string>() {  <field list> };
        WorkItem workItem = witClient.GetWorkItemAsync(_id, fields, null, null).Result;
        if (workItem.Fields.Count > 0)
        {
            foreach (string fld in workItem.Fields.Keys.ToList<string>())
            {
                if (fld == "Microsoft.VSTS.Scheduling.OriginalEstimate")
                {
                        OriginalEst = (double)workItem.Fields[fld];
                }
            <remaining if statements to get data>
            }
        }
}
Now we need to store the data so it can be then processed further by a TimeSheet application. The code to store in database is very straightforward as follows”
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = <connection string>;
cmd.Connection = con;
cmd.CommandText = "INSERT INTO TimeSheetData VALUES (@TaskID,@Title,@AssignedTo,@Original,@Completed)";
cmd.Parameters.Add("@TaskID", SqlDbType.Int).Value = task.Id;
cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value = title;
cmd.Parameters.Add("@AssignedTo", SqlDbType.NVarChar).Value = assignedTo;
cmd.Parameters.AddWithValue("@Original", SqlDbType.SmallInt).Value = OriginalEst;
cmd.Parameters.AddWithValue("@Completed", SqlDbType.SmallInt).Value = CompletedHrs;
con.Open();
cmd.ExecuteNonQuery();
con.Close();

Source: link

Recent Questions on azure-devops

    Programming Languages