Forum Discussion
Need help on rest api for creating a report
Hi, I need to create a jason report to extract list of release id and workitems related to the releases from all the projects areas in an organization. Please help me in any script you might have.
Try sample on below
import requests import json # Replace these variables with your Azure DevOps organization and personal access token organization = 'yourorganization' pat = 'yourpat' project = 'yourproject' # Base URL for Azure DevOps REST API base_url = f'https://dev.azure.com/{organization}/{project}/_apis/' # Headers for the request headers = { 'Content-Type': 'application/json', 'Authorization': f'Basic {pat}' } # Function to get releases def get_releases(): url = f'{base_url}release/releases?api-version=7.1-preview.6' response = requests.get(url, headers=headers) return response.json() # Function to get work items related to a release def get_work_items(release_id): url = f'{base_url}release/releases/{release_id}/workitems?api-version=7.1-preview.6' response = requests.get(url, headers=headers) return response.json() # Get all releases releases = get_releases() # Extract release IDs and related work items report = [] for release in releases['value']: release_id = release['id'] work_items = get_work_items(release_id) report.append({ 'release_id': release_id, 'work_items': work_items['value'] }) # Save the report to a JSON file with open('release_report.json', 'w') as f: json.dump(report, f, indent=4) print('Report generated successfully!')
- balasubramanimIron Contributor
To create a JSON report of release IDs and related work items from all projects in an Azure DevOps organization. Please try the below mentioned steps.
Steps
1. Authenticate: Use a Personal Access Token (PAT) for authentication2. Fetch Projects:
GET https://dev.azure.com/{organization}/_apis/projects?api-version=6.03. Get Releases for Each Project:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=6.04. Fetch Linked Work Items:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.05. Compile Data: Combine projects, releases, and work items into a JSON report
Python Script Example:
import requests
import jsonorg = "your_organization"
pat = "your_pat"
headers = {"Authorization": f"Basic {requests.auth._basic_auth_str('', pat)}"}# Fetch projects
projects = requests.get(f"https://dev.azure.com/{org}/_apis/projects?api-version=6.0", headers=headers).json()["value"]report = []
for project in projects:
project_name = project["name"]
releases = requests.get(f"https://vsrm.dev.azure.com/{org}/{project_name}/_apis/release/releases?api-version=6.0", headers=headers).json()["value"]for release in releases:
release_id = release["id"]
work_items = [] # Add logic to fetch work items linked to release
report.append({"project": project_name, "release_id": release_id, "work_items": work_items})# Save to JSON
with open("report.json", "w") as file:
json.dump(report, file, indent=4) - mamathalCopper Contributor
Thank you for the replies. Appreciate it!!