Azure DevOps rest api - Get work item by custom field - azure-devops

I am currently migrating from tfs 2015 to Azure DevOps, and I would like to use the REST Api services to get work items. In TFS were an option to include custom fields as filter in the http query to list work items, (e.g. there are many work items with custom field 'otherId', i want to list all the work items which otherId field value equals to 5) but in the Azure Devops api documentation i cannot find description about how to do this.
If it is possible, could you give me an example?
Tried to google it, read devops api documentation but i have not found any solution

You may use Query By Wiql. Your request may be like this:
POST https://TFS_SERVER:PORT/PROJECT/_apis/wit/wiql?api-version=7.1-preview.2
{
"query": "Select [System.Id] From WorkItems Where [YourCustomPath.otherId] = 'OTHER_ID'"
}
Check the example:
https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/wiql/query-by-wiql?view=azure-devops-rest-7.1&tabs=HTTP#examples
Additionally, check the API version here: API and TFS version mapping

Related

Azure DevOps - how can I retrieve the history of all my "Name" tags?

In Azure DevOps you can tag users with #HisName. How can I retrieve the history of all the comments where my name was tagged? Please not using emails notifications, but inside the Azure DevOps web site? Thanks!
I've searched and asked a couple colleagues but no ones knows.
For work items mentioned users in their comment field like this:
You could try to use 'history' contains 'user name' in a query to get the work item:
If you mean tag user like this in the tag:
Since the query doesn't support '#' symbol in the contains field, please don't use # in the tag or you couldn't query. Then you could query the tag like this and get the work item.
You could add these date according to your requirement to limit the time:

Fetch the data from Power BI related to username/emailId by whom Azure Pipeline was ran

"https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns?"
Using this url I am able to fetch RunNumber, RunReason but unable to fetch RunBy which user.
You could get the user that requested the run using predefined variables.
$(Build.RequestedFor)
And additionally you can also use
echo $(Build.RequestedForEmail)
echo $(Build.RequestedForId)
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#identity_values
There are some predefined variable for RunReason and BuildID as well.
$(Build.Reason)
$(Build.BuildId)
According to your description, I tried to get the odata feed "https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns" in Power BI, currently there is no option to fetch who trigger the pipeline. And check the REST API is also without this.
You could use "Request a feature" on the left side of Developer Community to open a new suggestion ticket.
For more information about who trigger the pipeline, you could refer to this.

Insert value into Azure DevOps Custom Fields through Rest Api

I've added some custom fields for Test Plan in Azure DevOps. But when I try to create a new Test Plan through the Rest API call, it is only creating a Test Plan with default fields populated, while custom fields remain blank.
I've tried using both the field name (like Team Name) along with field reference name (like custom.TeamName) but to no avail. Even Get is also not exposing custom fields. Is some extra configuration required for custom fields, or it is a code related issue?
Details: I've created one Inherited process under the organization, and then under Process->Test Plan I've created new fields in the Test Plan, as shown in the screen shot:
I've tried below code to create Test Plan as Work Item and successfully created it with extra fields. But as I couldn't create a test suite independently, it is not behaving properly.
I've created a JsonPatchDocument and added all the fields (adding just one here) like below code:
JsonPatchDocument patchDocument= new JsonPatchDocument();
patchDocument.Add(
{
Operation=Operation.Add,
Path="/fields/System.TeamName",
Value="Xander"
}
);
VssConnection connection=new VssConnection(uri,credential);
WorkItemTrackingHttpClient workItemTrackingHttpClient= connection.GetClient<WorkItemTrackingHTTPClient>();
WorkItem res=workItemTrackingHTTPClient.CreateWorkItemAsync(patchDocument,project,"Test Plan").Result;
It is creating the Test Plan, but not Test Suite. So it is acting weirdly. Kindly check this.
Insert value into Azure DevOps Custom Fields through Rest Api
I could reproduce this issue with the REST API Test Plans - Create.
I think this should be related to the REST API, that because even if I use the REST API Test Plans - Get to get the custom field, but the request body does not include the custom field.
Since we could not get the custom field, we could not use the POST or PATCH for the custom filed.
You could add this request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.

how to get all the Task in a Workitem in Json form by postman for TFS API

i am currently using TFS API who's link is
https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#byids
currently in my project i want to accees the following workitem 61092 all the task
http://apactfs.cbre.com:8080/tfs/CBRE.APAC.Applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092
for that i am using this link in postman GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/workitems/61092?$expand=all&api-version=1.0
i am getting all the task related to it but not getting all the field such as number of hours in the task,user of the task which i wanted.
and in Postman i am hitting the id by this Link By GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092&api-version=1.0
According to your screenshot, 61092 is a Product Backlog Item. The Rest API URL you use can only get the detailed information of the work item 61092 itself, it cannot get the detailed information about the work items that linked to 61092.
You have to use One-hop Query to get all the tasks related to it and then get the detailed data for each task returned. Refer to this link for details: Get Work Items.
$expand=all has already expand all fields, but it doesn't show the empty fields in response. If you type a value for the field you want to get, you will see it as expect in response.

Autocomplete testing on Azure Search explorer

I am trying to build and test the auto complete feature on a master item lookup tables using Azure Search (for a ASP MVC application). The search index was done with the suggesterName SG set to ItemDisplayName
I was looking to test it first on Azure portal- so that I could aim to replicate the results via code. This is because the results I am getting in code are quite unexpected
As I type the substring the itemDislayName, the expectation was that upto 5 selected names will be displayed
On the portal, I tried a query string of
search=str&suggesterName=SG
with the base request URL containing the index, api version and sugestorName-but I don't get results of items containing 'str' and with the fuzziness as below
Could you please guide around
[1] how I can get suggestor output in azure portal-search explorer
[2] can I control fuzziness using queryType and ~1,~2
I was referring to these 3 links
1) https://learn.microsoft.com/en-us/rest/api/searchservice/suggestions
and
2) https://channel9.msdn.com/Shows/Azure-Friday/Azure-Search-103-Azure-Search-Suggestions-with-Liam-Cavanagh
3) gunnarpeipman.com/2016/07/azure-search-suggesters/
Azure Search Portal doesn't support the Suggestion API yet. You will need to use an HTTP client like Fiddler or Postman.
Make sure you use the right URL for you Suggest requests:
https://[service name].search.windows.net/indexes/[index name]/docs/suggest
Please use our User Voice page to vote for adding the Suggest API to the Portal: https://feedback.azure.com/forums/263029-azure-search