Skip to content

Commit d7ed5ce

Browse files
committed
Refresh article
1 parent 43004b5 commit d7ed5ce

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

docs/service-hooks/create-subscription.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,36 @@ ms.date: 10/14/2022
1515

1616
[!INCLUDE [version-lt-eq-azure-devops](../includes/version-lt-eq-azure-devops.md)]
1717

18-
Using the [Subscriptions REST APIs](/rest/api/azure/devops/hooks/) , you can programmatically create a subscription that performs an action on an external/consumer service when a specific event occurs in an Azure DevOps project. For example, you can create a subscription to notify your service when a build fails.
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/).
1919

20-
Supported events:
20+
Azure DevOps provides support for numerous trigger events. Examples include the following events:
2121

2222
- Build completed
2323
- Code pushed (for Git projects)
24-
- Pull request create or updated (for Git projects)
25-
- Code checked in (TFVC projects)
26-
- Work item created, updated, deleted, restored or commented on
24+
- Pull request created or updated (for Git projects)
25+
- Code checked in (for Team Foundation Version Control projects)
26+
- Work item created, updated, deleted, restored, or commented on
2727

28-
You can configure filters on your subscriptions to control which events trigger an action. 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 the [Event reference](./events.md).
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).
2929

30-
For a complete set of supported consumer services and actions, see the [Consumer reference](./consumers.md).
30+
For a complete set of supported consumer services and actions, see [Service hook consumers](./consumers.md).
3131

3232
## Prerequisites
3333

3434
| Category | Requirements |
3535
|--------------|-------------|
3636
|**Project access**| [Project member](../organizations/security/add-users-team-project.md). |
37-
|**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 the [Event reference](./events.md).<br>- Consumer and action IDs and settings. See the [Consumer reference](./consumers.md).|
37+
|**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).|
3838

3939
## Create the request
4040

41-
Construct the body of the HTTP POST request to create the subscription based on the project ID, event, consumer, and action.
41+
When you create a subscription, the body of your HTTP POST request specifies the project ID, event, consumer, action, and related settings.
4242

43-
See the following example request for creating a subscription that causes a build event to POST to `https://myservice/event` when the build `WebSite.CI` fails.
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.
4444

4545
**Request**
46-
```js
46+
47+
```json
4748
{
4849
"publisherId": "tfs",
4950
"eventType": "build.complete",
@@ -53,7 +54,7 @@ See the following example request for creating a subscription that causes a buil
5354
"publisherInputs": {
5455
"buildStatus": "failed",
5556
"definitionName": "WebSite.CI",
56-
"projectId": "56479caf-1eeb-4bca-86ab-aaa6f29399d9",
57+
"projectId": "11bb11bb-cc22-dd33-ee44-55ff55ff55ff",
5758
},
5859
"consumerInputs": {
5960
"url": " https://myservice/event"
@@ -64,9 +65,10 @@ See the following example request for creating a subscription that causes a buil
6465
We highly recommend using secure HTTPS URLs for the security of the private data in the JSON object.
6566

6667
**Response**
67-
See the following response to the request to create the subscription:
6868

69-
```js
69+
The request to create the subscription generates a response that's similar to the following one:
70+
71+
```json
7072
{
7173
"id": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
7274
"url": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/hooks/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
@@ -76,19 +78,19 @@ See the following response to the request to create the subscription:
7678
"consumerId": "webHooks",
7779
"consumerActionId": "httpRequest",
7880
"createdBy": {
79-
"id": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc"
81+
"id": "22cc22cc-dd33-ee44-ff55-66aa66aa66aa"
8082
},
8183
"createdDate": "2014-03-28T16:10:06.523Z",
8284
"modifiedBy": {
83-
"id": "1c4978ae-7cc9-4efa-8649-5547304a8438"
85+
"id": "22cc22cc-dd33-ee44-ff55-66aa66aa66aa"
8486
},
8587
"modifiedDate": "2014-04-25T18:15:26.053Z",
8688
"publisherInputs": {
8789
"buildStatus": "failed",
8890
"definitionName": "WebSite.CI",
89-
"hostId": "17f27955-99bb-4861-9550-f2c669d64fc9",
90-
"projectId": "56479caf-1eeb-4bca-86ab-aaa6f29399d9",
91-
"tfsSubscriptionId": "29cde8b4-f37e-4ef9-a6d4-d57d526d82cc"
91+
"hostId": "d3d3d3d3-eeee-ffff-aaaa-b4b4b4b4b4b4",
92+
"projectId": "11bb11bb-cc22-dd33-ee44-55ff55ff55ff",
93+
"tfsSubscriptionId": "ffff5f5f-aa6a-bb7b-cc8c-dddddd9d9d9d"
9294
},
9395
"consumerInputs": {
9496
"url": "http://myservice/event"
@@ -101,21 +103,22 @@ If the subscription request fails, you get an HTTP response code of 400 with a m
101103

102104
### What happens when the event occurs?
103105

104-
When an event occurs, all enabled subscriptions in the project are evaluated, and the consumer action is performed for all matching subscriptions.
106+
When an event occurs, all enabled subscriptions in the project are evaluated. Then the consumer action is performed for all matching subscriptions.
105107

106108
### Resource versions (advanced)
107109

108110
Resource versioning is applicable when an API is in preview. For most scenarios, specifying `1.0` as the resource version is the safest route.
109111

110-
The event payload sent to certain consumers, like Webhooks, Azure Service Bus, and Azure Storage, includes a JSON representation of subject resource (for example, a build or work item). The representation of this resource can have different forms or versions.
112+
The event payload sent to certain consumers includes a JSON representation of a subject resource. For instance, the payload sent to webhooks, Azure Service Bus, and Azure Storage includes information about a build or work item. The representation of this resource can have various forms or versions.
113+
114+
You can specify the version of the resource that you want to send to the consumer service via the `resourceVersion` field on the subscription.
111115

112-
You can specify the version of the resource that you want to have sent to the consumer service via the `resourceVersion` field on the subscription.
113-
The resource version is the same as the [API version](../integrate/concepts/rest-api-versioning.md). Not specifying a resource version means "latest released". You should always specify a resource version, which ensures a consistent event payload over time.
116+
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.
114117

115118
## FAQs
116119
### Q: Are there services that I can subscribe to manually?
117120

118-
A: Yes. For more information about the services that you can subscribe to from the administration page for a project, see the [Overview](./overview.md).
121+
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).
119122

120123
### Q: Are there C# libraries that I can use to create subscriptions?
121124

@@ -211,7 +214,6 @@ namespace Microsoft.Samples.VisualStudioOnline
211214

212215
## Related articles
213216

214-
- [Authorize service hooks](authorize.md)
215-
- [Consumers](consumers.md)
216-
- [Events](events.md)
217-
- [Troubleshooting and FAQs](troubleshoot.md)
217+
- [Manage authorization of services to access Azure DevOps](authorize.md)
218+
- [Service hooks events](events.md)
219+
- [Troubleshoot service hooks](troubleshoot.md)

0 commit comments

Comments
 (0)