Skip to content

Instantly share code, notes, and snippets.

@chiguniiita
Created May 10, 2020 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiguniiita/1cafbe6296e4f048a8e95794323fec43 to your computer and use it in GitHub Desktop.
Save chiguniiita/1cafbe6296e4f048a8e95794323fec43 to your computer and use it in GitHub Desktop.
[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