如何通过Azure DevOps Api 5.1获取指定发布版本的工作项?
First off, the 404 error you’re hitting is because the endpoint https://vsrm.dev.azure.com/mycompany/myproject/_apis/release/releases/myreleaseid/workitems?api-version=5.1 doesn’t exist in API version 5.1. Azure DevOps doesn’t offer a direct endpoint to pull work items linked to a release—you’ll need to go through the release’s artifacts instead. Here are your actionable solutions:
Option 1: Fetch Work Items via Release Artifacts (Custom API Approach)
If you need to build custom notification logic, follow these steps:
Pull the release details first (you already have this working):
GET https://vsrm.dev.azure.com/mycompany/myproject/_apis/release/releases/myreleaseid?api-version=5.1In the response, look for the
artifactsarray. Each entry will have adefinitionReferencefield—for example, if your release uses a build artifact, this will include abuildIdvalue.Call the matching API based on your artifact type:
- For build artifacts: Use the build ID to fetch linked work items:
GET https://dev.azure.com/mycompany/myproject/_apis/build/builds/{buildId}/workitems?api-version=5.1 - For pull request artifacts: Use the repo ID and PR ID to get linked work items:
GET https://dev.azure.com/mycompany/myproject/_apis/git/repositories/{repoId}/pullRequests/{pullRequestId}/workitems?api-version=5.1
- For build artifacts: Use the build ID to fetch linked work items:
Double-check your Personal Access Token (PAT) has these permissions:
- Release: Read access (to fetch release details)
- Work Items: Read access (to pull work item data)
- Build/Git: Read access (depending on your artifact type)
Option 2: Use Azure DevOps Built-In Notifications (Easier, Low-Maintenance)
If your only goal is to notify work item stakeholders when a release completes, skip custom API code entirely. Azure DevOps has built-in tools for this:
- Go to your project → Click the gear icon in the top right → Select Notifications
- Click New subscription
- Under "What event do you want to subscribe to?", pick a release event like Release completed
- Add filters to target your specific release pipeline/stage (so you don’t get notifications for every release)
- In the "Who should receive the notification?" section, select Work item stakeholders and configure it to target work items linked to the release’s artifacts
- Save the subscription—Azure DevOps will automatically send notifications to the right people when the release finishes.
This approach avoids all API troubleshooting and is way less work long-term!
内容的提问来源于stack exchange,提问作者Mathias F

