We will fetch data using Work Item Query Language (WIQL).
WIQL query is like SQL query. The WIQL syntax is not case sensitive. It has the following clauses like:
- AND
- OR
- NOT
- UNDER
- SORT
WIQL syntax will never provide you detailed work item information, because to execute this, they use REST API, but that it doesn’t have an endpoint to provide such detailed info.
So, to get the detailed info we must follow 2 steps,
- Get Ids of work items using “WorkItemQueryResult”, which is the result of "QueryByWiqlAsync(wiql)". Here parameter wiql object consists of our search query.
- Once we get ids in “WorkItemReference” which will be IEnumerable type, then we can fetch all details using “GetWorkItemsAsync” method.
Create PAT token
To get started first we need a PAT token which is required to communicate with Azure DevOps. PAT is an alternative for password that you can use to authenticate into Azure DevOps. To create it go to Security, from the top left corner menu choose the “New Token”.
Then as per your requirement select the options, most of them are self-explanatory.

Important Note
Once you create token, copy it somewhere because it will not be available again.
Once you create token, copy it somewhere because it will not be available again.
Create C# Console App targeting .NET Framework 4.5.
Then add the below package from Nuget,
- Microsoft.VisualStudio.Services.Client
- Microsoft.TeamFoundationServer.Client
Now in main method use the below code,
- Uri orgUrl = new Uri("https://dev.azure.com/{Organization name}/");
- String personalAccessToken = "{pat token}";
- VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));
Just put your respective values instead of {Organization name}, {pat token} so you can access your DevOps server data.

deepak karmaPosted Jun 2, 2020, 12:35 AM
Using pat it always set my name as createdBy for workitem creating using code. Any service account can i use for this?
Arvind SinghPosted Oct 15, 2019, 12:02 AM
Nice article Nakul Chaudhari keep it up....