json可能是这样的:{ "consumerActionId":"httpRequest", "consumerId":"webHooks", "consumerInputs":{ "url":"XXX" }, "eventType":"workitem.created", "publisherId":"tfs", "publisherInputs":{ "areaPath":"[area path]", "workItemType":"Task", "projectId":"[project id]" }, "resourceVersion":"1.0"}第二,根据我的测试,我们无法使用OAuth令牌通过workitem.created EventType创建一个Webhook,它将引发该错误. (可以使用build.complete EventType创建一个Webhook).您可以改用个人访问令牌或备用帐户.我在此处提交反馈:使用workitem创建webhook.创建的EventType和OAuth令牌失败,您可以投票并关注. My API Request is as URL : https://kogul-ceymplon.visualstudio.com/_apis/hooks/subscriptions?api-version=4.1-previewMethod: POSTHeader : Bearer {accesToken}Code:'using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); ServiceHook hook = new ServiceHook(); hook.PublisherId = "tfs"; hook.EventType = "workitem.created"; hook.ResourceVersion = "1.0-preview.1"; hook.ConsumerId = "webHooks"; hook.ConsumerActionId = "httpRequest"; hook.PublisherInputs = new PublisherInput { projectId = "d028a77b-50c4-4bdc-943d-6b072799b884" }; hook.ConsumerInputs = new ConsumerInput { url= "https://myservice/newreceiver" }; var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string jsonString = javaScriptSerializer.Serialize(hook); var request = new HttpRequestMessage(HttpMethod.Post, "https://kogul-ceymplon.visualstudio.com/_apis/hooks/subscriptions?api-version=4.1-preview"); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); string ccc = request.Content.ReadAsStringAsync().Result; using (HttpResponseMessage response = client.SendAsync(request).Result) { response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); return responseBody; } }'What could be the fault at my side? 解决方案 First, the json is incorrect for workitem.created EventType, you need to specify area and task (Try to create a webhook manually and check the inputs)The json could be like this:{ "consumerActionId":"httpRequest", "consumerId":"webHooks", "consumerInputs":{ "url":"XXX" }, "eventType":"workitem.created", "publisherId":"tfs", "publisherInputs":{ "areaPath":"[area path]", "workItemType":"Task", "projectId":"[project id]" }, "resourceVersion":"1.0"}Secondly, based on my test, we can’t use OAuth token to create a webhook with workitem.created EventType, it will throw that error. (Can create a webhook with build.complete EventType) You can use personal access token or alternate account instead.I submit a feedback here: Create webhook with workitem.created EventType and OAuth token fail, you can vote and follow. 这篇关于通过Rest Api为工作项创建事件创建VSTS ServiceHooks(WebHooks)失败.请给一个解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 11:13