locked
Creating VSTS ServiceHooks (WebHooks) via Rest Api for work item created event fails. Please give a solution

    Question

  • My API Request is as 

    URL : https://kogul-ceymplon.visualstudio.com/_apis/hooks/subscriptions?api-version=4.1-preview

    Method: POST

    Content: "application/json" of "{\"PublisherId\":\"tfs\",\"EventType\":\"workitem.created\",\"ResourceVersion\":\"1.0-preview.1\",\"ConsumerId\":\"webHooks\",\"ConsumerActionId\":\"httpRequest\",\"PublisherInputs\":{\"ProjectId\":\"d028a77b-50c4-4bdc-943d-6b072799b884\"},\"ConsumerInputs\":{\"Url\":\"https://myservice/newreceiver\"}}"

    Header : Bearer {accesToken}

    My Response is as  

    {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: 31deba9c-369c-4a31-9be3-67af8ce6249e.","typeName":"System.Exception, mscorlib","typeKey":"Exception","errorCode":0,"eventId":0}


    What could be the fault at my side?

    Thursday, November 9, 2017 5:07 PM

All replies

  • Hi Kogul,

    The REST distinguish lowercase and uppercase, try to modify the body request to the following format:

    "{\"PublisherId\":\"tfs\",\"EventType\":\"workitem.created\",\"ResourceVersion\":\"1.0-preview.1\",\"ConsumerId\":\"webHooks\",\"ConsumerActionId\":\"httpRequest\",\"PublisherInputs\":{\"projectId\":\"d028a77b-50c4-4bdc-943d-6b072799b884\"},\"ConsumerInputs\":{\"url\":\"https://myservice/newreceiver\"}}"

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, November 10, 2017 8:30 AM
  • Thanks.. I modified the post request as you mentioned but the change didn't work. The response is again the same

    {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: f9f3fd1c-a8f5-4618-bcc3-74de2c623d71.","typeName":"System.Exception, mscorlib","typeKey":"Exception","errorCode":0,"eventId":0}

    Friday, November 10, 2017 9:55 AM
  • 

    Hi Kogul,

    Are you able to create a servicehook from VSTS web portal?

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, November 13, 2017 1:46 AM
  • Hi Xinxin Dong,

    Yes, I can create service hooks for build complete event. But ServiceHook for WorkItem created event is failing.
    • Edited by Kogul Monday, November 13, 2017 3:31 AM
    Monday, November 13, 2017 3:28 AM
  • Hi Kogul,

    Do you mean you also get error when you create a ServiceHook for WorkItem created? Could you share you detailed steps and error message?

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, November 13, 2017 8:51 AM
  • Hi Xinxin Dong,

    Yes, The steps are
    1. I created an application and with all scopes provided in VSTS.
    2. I created a web application from which I got the access token using client secret.
    3. By providing access token in the headers Via API Request, I am able to create the service hook for the build.completed event but not for workitem.created.
    The code sample of API Request is as follows:

    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");

                        using (HttpResponseMessage response = client.SendAsync(request).Result)
                        {
                            response.EnsureSuccessStatusCode();
                            string responseBody = await response.Content.ReadAsStringAsync();
                            return responseBody;
                        }
                    }

    Monday, November 13, 2017 10:10 AM