简体   繁体   English

如何通过 azure-devops-python-api 获取仪表板列表

[英]How to get a list of dashboards through azure-devops-python-api

I am trying to get a list of dashboards using azure-devops-python-api .我正在尝试使用azure-devops-python-api获取仪表板列表。 I can't figure out how to connect the libraries correctly to get the list of dashboards and work with them.我不知道如何正确连接库以获取仪表板列表并使用它们。 What I've done is this:我所做的是这样的:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0 import DashboardClient 
import pprint
import requests
import json

personal_access_token = 'PAT'
organization_url = 'https://dev.azure.com/Orgname/'
team_context = 'Orgname'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

dashboard_resp = DashboardClient(base_url=organization_url, creds=credentials)
dashboards = dashboard_resp.get_dashboards_by_project('', team_context)

When I try to execute this code, I get an error当我尝试执行此代码时,出现错误

Traceback (most recent call last):
  File "az-dev-dash.py", line 16, in <module>
    dashboard_resp = azure.DashboardClient(base_url=organization_url, creds=credentials)
AttributeError: module 'azure.devops.v6_0' has no attribute 'DashboardClient'

You can use the below Python script to list the dashboards in a particular project using python.您可以使用下面的 Python 脚本列出使用 python 的特定项目中的仪表板。

Here is the python code:这是 python 代码:

from re import T
from azure.devops.connection import Connection
from azure.devops.v6_0.dashboard.models import Dashboard, TeamContext
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.dashboard.dashboard_client import DashboardClient 
import pprint
import requests
import json

personal_access_token = '<PATToken>'
organization_url = 'https://dev.azure.com/<OrgnName>' ##OrganisationalUrl

team_context=TeamContext('<projectName>')

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
core_client = connection.clients.get_core_client()
dashboard_resp = DashboardClient(base_url=organization_url, creds=credentials)
dashboards = dashboard_resp.get_dashboards_by_project(team_context)
for item in dashboards:
 print(item)

Here is the sample output for reference:以下是样品 output 供参考:

在此处输入图像描述

Alternatively, you can this Rest API, to list the dashboards in the project .或者,您可以使用Rest API list the dashboards in the project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 azure-devops-python-api 查询工作项,其中字段 == 字符串 - azure-devops-python-api query for work item where field == string API 使用 python 调用 Azure DevOps 以获取组织中的用户列表 - API call using python to Azure DevOps to get list of users in an organization 如何使用Azure DevOps Python API获取项目列表? - How do I get the list of projects using the Azure DevOps Python API? 如何使用 Azure DevOps 下载 Azure 通用包 - How to download Azure universal packages using Azure DevOps Python API AttributeError: &#39;list&#39; 对象没有属性 &#39;value&#39; - 用于 Azure DevOps 的 Python API - AttributeError: 'list' object has no attribute 'value' - Python API for Azure DevOps 如何编写 Python 脚本以对 Azure DevOps REST API 进行身份验证并获取访问令牌? - How to write a python script to authenticate to Azure DevOps REST API and get the access token? 如何使用 Python REST API 在 Azure DevOps 中更新测试结果? - How to Update Test Results in Azure DevOps with Python REST API? 如何使用Python REST API在Azure DevOps中检索测试结果? - How to retrieve Test Results in Azure DevOps with Python REST API? 如何使用它的 python 客户端 API 将用户添加到 Azure DevOps? - How to add a user to Azure DevOps using it's python client API? 如何使用 python api 添加 azure devops 迭代路径选项 - how to add azure devops iteration path option with python api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM