public Subscription CreateDeleteRMWebHooksSubscription()
        {
            // Get the project to create the subscription in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            // Get the list of publishers
            IList <VisualStudio.Services.ServiceHooks.WebApi.Publisher> publishers = serviceHooksClient.GetPublishersAsync().Result;

            // Find the Release Management publisher and get its ServiceInstanceType
            VisualStudio.Services.ServiceHooks.WebApi.Publisher rmPublisher = publishers.First(p => p.Id == "rm");
            Guid rmServiceInstance = Guid.Parse(rmPublisher.ServiceInstanceType);

            // Get a new client using the RM ServiceInstanceType
            ServiceHooksPublisherHttpClient rmServiceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>(rmServiceInstance);

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType       = "ms.vss-release.release-created-event",
                PublisherId     = "rm",
                PublisherInputs = new Dictionary <string, string>
                {
                    { "projectId", project.Id.ToString() }
                },
            };
            Subscription newSubscription = rmServiceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            rmServiceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = rmServiceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            }
            catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }
        public Subscription CreateDeleteWebHooksSubscription()
        {
            // Get the project to create the subscription in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType       = "workitem.created",
                PublisherId     = "tfs",
                PublisherInputs = new Dictionary <string, string>
                {
                    { "projectId", project.Id.ToString() }
                },
            };

            Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            } catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }
        public Subscription CreateDeleteAccountWideWebHooksSubscription()
        {
            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType   = "workitem.updated",
                PublisherId = "tfs"
            };

            Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            }
            catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }