You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/service-hooks/create-subscription.md
+93-98Lines changed: 93 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,33 @@
1
1
---
2
-
title: Create a service hook subscription programmatically
3
-
description: Use service hooks to set up actions to take when specific events occur in Azure DevOps.
2
+
title: Create a Service Hook Subscription Programmatically
3
+
description: Find out how to programmatically create a service hook subscription that configures an action to take when a specific event occurs in Azure DevOps.
4
4
ms.assetid: 0614F217-4F4E-45DC-A50C-B9FF81F8A5BD
5
5
ms.custom: engagement-fy23
6
6
ms.subservice: azure-devops-service-hooks
7
-
ms.topic: conceptual
7
+
ms.topic: how-to
8
8
ms.author: chcomley
9
9
author: chcomley
10
10
monikerRange: '<= azure-devops'
11
-
ms.date: 10/14/2022
11
+
ms.date: 06/25/2025
12
+
# customer intent: As a developer, I want to create a service hook subscription programmatically so that I can automate tasks in other services when events happen in my Azure DevOps project.
12
13
---
13
14
14
15
# Create a service hook subscription programmatically
[!INCLUDE [Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020](../includes/version-gt-eq-2020.md)]
17
18
18
-
You can use a subscription to perform an action on an external or consumer service when a specific event occurs in an Azure DevOps project. For example, a subscription can notify your service when a build fails. To create a subscription programmatically, you can use the [Subscriptions REST APIs](/rest/api/azure/devops/hooks/).
19
+
You can use a subscription to perform an action on an external or consumer service when a specific event occurs in an Azure DevOps project. For example, a subscription can notify your service when a build fails.
20
+
21
+
To create a subscription programmatically, you can use the [Subscriptions REST APIs](/rest/api/azure/devops/hooks/). This article provides a sample request and sample code for creating a subscription.
|**Data**|- Project ID. Use the [Project REST API](/rest/api/azure/devops/core/projects) to get the project ID.<br>- Event ID and settings. See [Service hook events](events.md).<br>- Consumer and action IDs and settings. See [Service hook consumers](consumers.md).|
29
+
30
+
## Supported events
19
31
20
32
Azure DevOps provides support for numerous trigger events. Examples include the following events:
21
33
@@ -25,22 +37,16 @@ Azure DevOps provides support for numerous trigger events. Examples include the
25
37
- Code checked in (for Team Foundation Version Control projects)
26
38
- Work item created, updated, deleted, restored, or commented on
27
39
28
-
To control which events trigger an action, you can configure filters on your subscriptions. For example, you can filter the build completed event based on the build status. For a complete set of supported events and filter options, see [Service hook events](./events.md).
40
+
To control which events trigger an action, you can configure filters on your subscriptions. For example, you can filter the build completed event based on the build status.
29
41
30
-
For a complete set of supported consumer services and actions, see [Service hook consumers](./consumers.md).
42
+
- For a complete set of supported events and filter options, see [Service hook events](events.md).
43
+
- For a complete set of supported consumer services and actions, see [Service hook consumers](consumers.md).
|**Data**|- Project ID. Use the [Project REST API](/rest/api/azure/devops/core/projects) to get the project ID.<br>- Event ID and settings. See [Service hook events](./events.md).<br>- Consumer and action IDs and settings. See [Service hook consumers](./consumers.md).|
47
+
When you create a subscription, you use the body of an HTTP POST request to specify the project ID, event, consumer, action, and related settings.
38
48
39
-
## Create the request
40
-
41
-
When you create a subscription, the body of your HTTP POST request specifies the project ID, event, consumer, action, and related settings.
42
-
43
-
You can use the following request to create a subscription for a build completed event. It sends a POST request to `https://myservice/event` when the `WebSite.CI` build fails.
49
+
You can use the following request to create a subscription for a build completed event. In this example, when the `WebSite.CI` build fails, the subscription sends a POST request to `https://myservice/event`.
44
50
45
51
**Request**
46
52
@@ -116,103 +122,92 @@ You can specify the version of the resource that you want to send to the consume
116
122
The resource version is the same as the [API version](../integrate/concepts/rest-api-versioning.md). If you don't specify a resource version, the latest version, `latest released`, is used. To help ensure a consistent event payload over time, always specify a resource version.
117
123
118
124
## FAQs
125
+
119
126
### Q: Are there services that I can subscribe to manually?
120
127
121
128
A: Yes. For more information about the services that you can subscribe to from a project administration page, see [Integrate with service hooks](overview.md).
122
129
123
130
### Q: Are there C# libraries that I can use to create subscriptions?
124
131
125
-
A: No, but here's a sample to help you get started.
132
+
A: No, but here's a sample to help you get started. For authentication to Azure DevOps, the following code uses a personal access token (PAT) that's stored in Azure Key Vault. In a production environment, use a more secure authentication method. For more information, see [Choose the right authentication mechanism](../integrate/get-started/authentication/authentication-guidance.md).
0 commit comments