Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Azure DevOps] REST API で作業項目を取得する
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace GetWorkItem
{
class Program
{
static async Task Main(string[] args)
{
var pat = "";
var organization = "";
var project = "";
var id = 0;
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($":{pat}")));
//https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/get%20work%20item?view=azure-devops-rest-5.1
var r = await httpClient.GetAsync($"https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=5.1");
var json = await r.Content.ReadAsStringAsync();
Console.WriteLine(FormatJson(json));
}
public static string FormatJson(string jsonText)
{
var o = JsonConvert.DeserializeObject(jsonText);
return JsonConvert.SerializeObject(o, new JsonSerializerSettings { Formatting = Formatting.Indented });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment