As a Microsoft Azure DevOps consultant, I have encountered a situation where I need to map generated IDs with boards from which these columns are coming from. In this blog post, I will discuss the issue and provide a solution to retrieve the details of the corresponding board based on the generated ID.
Issue Description:
I have two Kanban team boards under a project in Azure DevOps, and there is a story item that has a shared area path between these two boards. To retrieve this item, I am using the Wit Work Items API, which returns two columns with generated IDs “WEF_34545787865766_Kanban.Column” and “WEF_785DDB2D72A74EBCB0E642E4A45F12EC_Kanban.Column”. My question is, how can I map these generated IDs with the boards from which these columns are coming from?
Background Information:
Azure DevOps provides a Wit Work Items API that allows us to retrieve work items based on their ID or other criteria. The API returns a JSON object containing information about the work item, such as its ID, name, description, and state. However, when we use the API to retrieve columns from multiple boards, it returns generated IDs for each board, which can make it challenging to map these IDs with the corresponding boards.
Solution:
To map the generated IDs with the boards, we need to use the Azure DevOps REST API to retrieve the board details based on the generated IDs. Here’s how we can do it:
Step 1: Retrieve the generated IDs for each column using the Wit Work Items API.
Step 2: For each generated ID, call the Azure DevOps REST API to retrieve the board details. We can use the “boards” endpoint to retrieve the details of all boards in the project, and then filter the results based on the generated ID.
Here’s an example of how we can implement this solution using PowerShell:
“`powershell
# Step 1: Retrieve the generated IDs for each column
$witApiUrl = “https://dev.azure.com/tasktop-sync-demo/Test Board Column/_apis/wit/workItems?id=5792498&api-version=6.1”
$response = Invoke-WebRequest -Uri $witApiUrl -Method Get -Headers @{Authorization = “Bearer $env:SYSTEM_ACCESSTOKEN”}
$generatedIds = $response.Content | ConvertFrom-Json
# Step 2: Retrieve the board details for each generated ID
$boardsUrl = “https://dev.azure.com/tasktop-sync-demo/Boards?api-version=6.1”
$boardsResponse = Invoke-WebRequest -Uri $boardsUrl -Method Get -Headers @{Authorization = “Bearer $env:SYSTEM_ACCESSTOKEN”}
$boards = $boardsResponse.Content | ConvertFrom-Json
# Map the generated IDs with the board details
foreach ($generatedId in $generatedIds) {
foreach ($board in $boards) {
if ($board.id -eq $generatedId.boardId) {
$boardDetails = $board | Select-Object -ExpandProperty name, description, id
Write-Host “Mapped generated ID $($generatedId.id) to board $($boardDetails.name)”
break
}
}
}
“`
In this example, we first retrieve the generated IDs for each column using the Wit Work Items API. We then use the Azure DevOps REST API to retrieve the board details for each generated ID. Finally, we map the generated IDs with the board details and display the results.
Conclusion:
In this blog post, we discussed a situation where we need to map generated IDs with boards from which these columns are coming from. We provided a solution using the Azure DevOps REST API and PowerShell to retrieve the board details based on the generated IDs. This solution can be useful when working with multiple boards in Azure DevOps and need to retrieve information about the corresponding boards based on generated IDs.