如何使用azure devops python api.需要一些例子:获取用户故事信息,创建用户故事,改变状态



我有一个完全满足我需求的程序,我没有使用库来编写它。我不小心删除了文件。使用版本控制。总是这样。

我正试图得到一个任务列表,但我完全不明白我在做什么。有人能举例子吗?我需要几个简单的操作:创建用户故事与标签,获取用户故事信息(标题,desc, id),改变用户故事状态(活动,关闭)

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.work_item_tracking.work_item_tracking_client import WorkItemTrackingClient
import pprint
from azure.devops.v6_0.work_item_tracking.models import WorkItemBatchGetRequest
m_token = "x7micezp4c25btn3a1111111111111o23zlxuwrpdoa"
m_url = 'https://dev.azure.com/logistics/'
m_cred = BasicAuthentication('', m_token)
m_conn = Connection(base_url=m_url, creds=m_cred)
m_client = m_conn.clients.get_core_client()

kek = WorkItemBatchGetRequest(ids = [22, 33])
cc = WorkItemTrackingClient(m_url)
c = cc.get_work_items_batch(kek, "Manyport")
print(c.value)

感谢Tom支持你的回答,并附上了如何在功能应用设置中添加用户身份的截图。

提供对服务资源的创建、检索、更新或删除访问的Rest API也支持HTTP操作,是服务端点。

下面是带有HTTP客户端类的Rest API示例代码。

public static async void GetProjects()
{
try
{
var personalaccesstoken = "PAT_FROM_WEBSITE";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalaccesstoken))));
using (HttpResponseMessage response = await client.GetAsync(
"https://dev.azure.com/{organization}/_apis/projects"))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

有关更多信息,请查看Azure DevOps with Rest API