我正在尝试以编程方式在Visual Studio Team Services(以前的Visual Studio Online)中创建服务挂钩订阅.在Team Services中创建项目时,将自动创建服务挂钩.以下是我的'workitem created'web钩子的代码:
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", username, password))));
var request = new
{
publisherId = "tfs",
eventType= " workitem.created",
resourceVersion= "1.0",
consumerId= "webHooks",
consumerActionId= "httpRequest",
publisherInputs= new {
projectId= "test123",
},
consumerInputs= new {
url = "https://mydomain/api/ServiceHook/SaveWorkItem"
}
};
var response = client.PostAsync("https://mydomain/DefaultCollection/_apis/hooks/subscriptions",
new StringContent(JsonConvert.SerializeObject(request).ToString(),
Encoding.UTF8, "application/json"))
.Result;
if (response.IsSuccessStatusCode)
{
dynamic content = JsonConvert.DeserializeObject(
response.Content.ReadAsStringAsync()
.Result);
// Access variables from …Run Code Online (Sandbox Code Playgroud)