Create or update an event subscription.
Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
PUT https://management.azure.com/{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}?api-version=2022-06-15
URI Parameters
Name |
In |
Required |
Type |
Description |
eventSubscriptionName
|
path |
True
|
string
|
Name of the event subscription. Event subscription names must be between 3 and 64 characters in length and should use alphanumeric letters only.
|
scope
|
path |
True
|
string
|
The identifier of the resource to which the event subscription needs to be created or updated. The scope can be a subscription, or a resource group, or a top level resource belonging to a resource provider namespace, or an EventGrid topic. For example, use '/subscriptions/{subscriptionId}/' for a subscription, '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a resource group, and '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}' for a resource, and '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}' for an EventGrid topic.
|
api-version
|
query |
True
|
string
|
Version of the API to be used with the client request.
|
Request Body
Name |
Type |
Description |
properties.deadLetterDestination
|
DeadLetterDestination:
StorageBlobDeadLetterDestination
|
The dead letter destination of the event subscription. Any event that cannot be delivered to its' destination is sent to the dead letter destination.
Uses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.deadLetterWithResourceIdentity
|
DeadLetterWithResourceIdentity
|
The dead letter destination of the event subscription. Any event that cannot be delivered to its' destination is sent to the dead letter destination.
Uses the managed identity setup on the parent resource (namely, topic or domain) to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.deliveryWithResourceIdentity
|
DeliveryWithResourceIdentity
|
Information about the destination where events have to be delivered for the event subscription.
Uses the managed identity setup on the parent resource (namely, topic or domain) to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.destination
|
EventSubscriptionDestination:
|
Information about the destination where events have to be delivered for the event subscription.
Uses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.eventDeliverySchema
|
EventDeliverySchema
|
The event delivery schema for the event subscription.
|
properties.expirationTimeUtc
|
string
|
Expiration time of the event subscription.
|
properties.filter
|
EventSubscriptionFilter
|
Information about the filter for the event subscription.
|
properties.labels
|
string[]
|
List of user defined labels.
|
properties.retryPolicy
|
RetryPolicy
|
The retry policy for events. This can be used to configure maximum number of delivery attempts and time to live for events.
|
Responses
Name |
Type |
Description |
201 Created
|
EventSubscription
|
EventSubscription CreateOrUpdate request accepted.
|
Other Status Codes
|
|
*** Error Responses: ***
|
Examples
EventSubscriptions_CreateOrUpdateForCustomTopic
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventHubEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopic(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new EventHubEventSubscriptionDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false)),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopic() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
Destination: &armeventgrid.EventHubEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeEventHub),
Properties: &armeventgrid.EventHubEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopic() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
destination: {
endpointType: "EventHub",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new EventHubEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"endpointBaseUrl": "https://requestb.in/15ksip71"
},
"endpointType": "WebHook"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"provisioningState": "Succeeded",
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/microsoft.eventgrid/topics/exampletopic1"
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.AzureFunctionEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicAzureFunctionDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new AzureFunctionEventSubscriptionDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_azure_function_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicAzureFunctionDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.AzureFunctionEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeAzureFunction),
Properties: &armeventgrid.AzureFunctionEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicAzureFunctionDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "AzureFunction",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_AzureFunctionDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new AzureFunctionEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Web/sites/ContosoSite/funtions/ContosoFunc"
},
"endpointType": "AzureFunction"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventHubEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicEventHubDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new EventHubEventSubscriptionDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_event_hub_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicEventHubDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.EventHubEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeEventHub),
Properties: &armeventgrid.EventHubEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicEventHubDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "EventHub",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_EventHubDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new EventHubEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/ContosoNamespace/eventhubs/EH1"
},
"endpointType": "EventHub"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "HybridConnection",
"properties": {
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.HybridConnectionEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicHybridConnectionDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new HybridConnectionEventSubscriptionDestination()
.withResourceId(
"/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_hybrid_connection_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "HybridConnection",
"properties": {
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicHybridConnectionDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.HybridConnectionEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeHybridConnection),
Properties: &armeventgrid.HybridConnectionEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicHybridConnectionDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "HybridConnection",
resourceId:
"/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_HybridConnectionDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new HybridConnectionEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Relay/namespaces/ContosoNamespace/hybridConnections/HC1"
},
"endpointType": "HybridConnection"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "ServiceBusQueue",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.ServiceBusQueueEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusQueueDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new ServiceBusQueueEventSubscriptionDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_service_bus_queue_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "ServiceBusQueue",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusQueueDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.ServiceBusQueueEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeServiceBusQueue),
Properties: &armeventgrid.ServiceBusQueueEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusQueueDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "ServiceBusQueue",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusQueueDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new ServiceBusQueueEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/queues/SBQ"
},
"endpointType": "ServiceBusQueue"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "ServiceBusTopic",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.ServiceBusTopicEventSubscriptionDestination;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusTopicDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new ServiceBusTopicEventSubscriptionDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_service_bus_topic_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "ServiceBusTopic",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusTopicDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.ServiceBusTopicEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeServiceBusTopic),
Properties: &armeventgrid.ServiceBusTopicEventSubscriptionDestinationProperties{
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicServiceBusTopicDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "ServiceBusTopic",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_ServiceBusTopicDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new ServiceBusTopicEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ContosoNamespace/topics/SBT"
},
"endpointType": "ServiceBusTopic"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "StorageQueue",
"properties": {
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"queueName": "queue1"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.StorageBlobDeadLetterDestination;
import com.azure.resourcemanager.eventgrid.models.StorageQueueEventSubscriptionDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicStorageQueueDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new StorageQueueEventSubscriptionDestination()
.withResourceId(
"/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withQueueName("queue1"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false))
.withDeadLetterDestination(
new StorageBlobDeadLetterDestination()
.withResourceId(
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg")
.withBlobContainerName("contosocontainer")),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_storage_queue_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"blobContainerName": "contosocontainer",
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"destination": {
"endpointType": "StorageQueue",
"properties": {
"queueName": "queue1",
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicStorageQueueDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
DeadLetterDestination: &armeventgrid.StorageBlobDeadLetterDestination{
EndpointType: to.Ptr(armeventgrid.DeadLetterEndPointTypeStorageBlob),
Properties: &armeventgrid.StorageBlobDeadLetterDestinationProperties{
BlobContainerName: to.Ptr("contosocontainer"),
ResourceID: to.Ptr("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Destination: &armeventgrid.StorageQueueEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeStorageQueue),
Properties: &armeventgrid.StorageQueueEventSubscriptionDestinationProperties{
QueueName: to.Ptr("queue1"),
ResourceID: to.Ptr("/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicStorageQueueDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
deadLetterDestination: {
blobContainerName: "contosocontainer",
endpointType: "StorageBlob",
resourceId:
"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
destination: {
endpointType: "StorageQueue",
queueName: "queue1",
resourceId:
"/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_StorageQueueDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new StorageQueueEventSubscriptionDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
QueueName = "queue1",
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
DeadLetterDestination = new StorageBlobDeadLetterDestination()
{
ResourceId = new ResourceIdentifier("/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg"),
BlobContainerName = "contosocontainer",
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"resourceId": "/subscriptions/d33c5f7a-02ea-40f4-bf52-07f17e84d6a8/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"queueName": "queue1"
},
"endpointType": "StorageQueue"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"provisioningState": "Creating",
"labels": null,
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": {
"resourceId": "/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/contosostg",
"blobContainerName": "contosocontainer"
}
}
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.WebhookEventSubscriptionDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForCustomTopicWebhookDestination(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
"examplesubscription1",
new EventSubscriptionInner()
.withDestination(
new WebhookEventSubscriptionDestination()
.withEndpointUrl(
"https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false)),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_custom_topic_webhook_destination.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1",
event_subscription_name="examplesubscription1",
event_subscription_info={
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE"
},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForCustomTopicWebhookDestination() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1", "examplesubscription1", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
Destination: &armeventgrid.WebHookEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeWebHook),
Properties: &armeventgrid.WebHookEventSubscriptionDestinationProperties{
EndpointURL: to.Ptr("https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.json
*/
async function eventSubscriptionsCreateOrUpdateForCustomTopicWebhookDestination() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
const eventSubscriptionName = "examplesubscription1";
const eventSubscriptionInfo = {
destination: {
endpointType: "WebHook",
endpointUrl:
"https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForCustomTopic_WebhookDestination.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription1";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new WebHookEventSubscriptionDestination()
{
Endpoint = new Uri("https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger1&code=PASSWORDCODE"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"endpointBaseUrl": "https://azurefunctionexample.azurewebsites.net/runtime/webhooks/EventGrid"
},
"endpointType": "WebHook"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"provisioningState": "Succeeded",
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/microsoft.eventgrid/topics/exampletopic1"
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/topics/exampletopic1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription1",
"name": "examplesubscription1",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForResource
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription10?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://requestb.in/15ksip71"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.WebhookEventSubscriptionDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResource.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForResource.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForResource(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1",
"examplesubscription10",
new EventSubscriptionInner()
.withDestination(
new WebhookEventSubscriptionDestination().withEndpointUrl("https://requestb.in/15ksip71"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false)),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1",
event_subscription_name="examplesubscription10",
event_subscription_info={
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {"endpointUrl": "https://requestb.in/15ksip71"},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResource.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1", "examplesubscription10", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
Destination: &armeventgrid.WebHookEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeWebHook),
Properties: &armeventgrid.WebHookEventSubscriptionDestinationProperties{
EndpointURL: to.Ptr("https://requestb.in/15ksip71"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResource.json
*/
async function eventSubscriptionsCreateOrUpdateForResource() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1";
const eventSubscriptionName = "examplesubscription10";
const eventSubscriptionInfo = {
destination: {
endpointType: "WebHook",
endpointUrl: "https://requestb.in/15ksip71",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResource.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription10";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new WebHookEventSubscriptionDestination()
{
Endpoint = new Uri("https://requestb.in/15ksip71"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"endpointBaseUrl": "https://requestb.in/15ksip71"
},
"endpointType": "WebHook"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"provisioningState": "Succeeded",
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1"
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventHub/namespaces/examplenamespace1/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription10",
"name": "examplesubscription10",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForResourceGroup
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription2?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://requestb.in/15ksip71"
}
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.WebhookEventSubscriptionDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResourceGroup.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForResourceGroup.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForResourceGroup(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg",
"examplesubscription2",
new EventSubscriptionInner()
.withDestination(
new WebhookEventSubscriptionDestination().withEndpointUrl("https://requestb.in/15ksip71"))
.withFilter(
new EventSubscriptionFilter()
.withSubjectBeginsWith("ExamplePrefix")
.withSubjectEndsWith("ExampleSuffix")
.withIsSubjectCaseSensitive(false)),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_resource_group.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg",
event_subscription_name="examplesubscription2",
event_subscription_info={
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {"endpointUrl": "https://requestb.in/15ksip71"},
},
"filter": {
"isSubjectCaseSensitive": False,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix",
},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResourceGroup.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResourceGroup.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForResourceGroup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg", "examplesubscription2", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
Destination: &armeventgrid.WebHookEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeWebHook),
Properties: &armeventgrid.WebHookEventSubscriptionDestinationProperties{
EndpointURL: to.Ptr("https://requestb.in/15ksip71"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
SubjectBeginsWith: to.Ptr("ExamplePrefix"),
SubjectEndsWith: to.Ptr("ExampleSuffix"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResourceGroup.json
*/
async function eventSubscriptionsCreateOrUpdateForResourceGroup() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg";
const eventSubscriptionName = "examplesubscription2";
const eventSubscriptionInfo = {
destination: {
endpointType: "WebHook",
endpointUrl: "https://requestb.in/15ksip71",
},
filter: {
isSubjectCaseSensitive: false,
subjectBeginsWith: "ExamplePrefix",
subjectEndsWith: "ExampleSuffix",
},
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForResourceGroup.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription2";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new WebHookEventSubscriptionDestination()
{
Endpoint = new Uri("https://requestb.in/15ksip71"),
},
Filter = new EventSubscriptionFilter()
{
SubjectBeginsWith = "ExamplePrefix",
SubjectEndsWith = "ExampleSuffix",
IsSubjectCaseSensitive = false,
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"endpointBaseUrl": "https://requestb.in/15ksip71"
},
"endpointType": "WebHook"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "ExamplePrefix",
"subjectEndsWith": "ExampleSuffix"
},
"provisioningState": "Succeeded",
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg"
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/examplerg/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription2",
"name": "examplesubscription2",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
EventSubscriptions_CreateOrUpdateForSubscription
Sample request
PUT https://management.azure.com/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription3?api-version=2022-06-15
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://requestb.in/15ksip71"
}
},
"filter": {
"isSubjectCaseSensitive": false
}
}
}
import com.azure.core.util.Context;
import com.azure.resourcemanager.eventgrid.fluent.models.EventSubscriptionInner;
import com.azure.resourcemanager.eventgrid.models.EventSubscriptionFilter;
import com.azure.resourcemanager.eventgrid.models.WebhookEventSubscriptionDestination;
/** Samples for EventSubscriptions CreateOrUpdate. */
public final class Main {
/*
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForSubscription.json
*/
/**
* Sample code: EventSubscriptions_CreateOrUpdateForSubscription.
*
* @param manager Entry point to EventGridManager.
*/
public static void eventSubscriptionsCreateOrUpdateForSubscription(
com.azure.resourcemanager.eventgrid.EventGridManager manager) {
manager
.eventSubscriptions()
.createOrUpdate(
"subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4",
"examplesubscription3",
new EventSubscriptionInner()
.withDestination(
new WebhookEventSubscriptionDestination().withEndpointUrl("https://requestb.in/15ksip71"))
.withFilter(new EventSubscriptionFilter().withIsSubjectCaseSensitive(false)),
Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventgrid import EventGridManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventgrid
# USAGE
python event_subscriptions_create_or_update_for_subscription.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventGridManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.event_subscriptions.begin_create_or_update(
scope="subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4",
event_subscription_name="examplesubscription3",
event_subscription_info={
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {"endpointUrl": "https://requestb.in/15ksip71"},
},
"filter": {"isSubjectCaseSensitive": False},
}
},
).result()
print(response)
# x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForSubscription.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventgrid_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/f88928d723133dc392e3297e6d61b7f6d10501fd/specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForSubscription.json
func ExampleEventSubscriptionsClient_BeginCreateOrUpdate_eventSubscriptionsCreateOrUpdateForSubscription() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventgrid.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewEventSubscriptionsClient().BeginCreateOrUpdate(ctx, "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4", "examplesubscription3", armeventgrid.EventSubscription{
Properties: &armeventgrid.EventSubscriptionProperties{
Destination: &armeventgrid.WebHookEventSubscriptionDestination{
EndpointType: to.Ptr(armeventgrid.EndpointTypeWebHook),
Properties: &armeventgrid.WebHookEventSubscriptionDestinationProperties{
EndpointURL: to.Ptr("https://requestb.in/15ksip71"),
},
},
Filter: &armeventgrid.EventSubscriptionFilter{
IsSubjectCaseSensitive: to.Ptr(false),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventGridManagementClient } = require("@azure/arm-eventgrid");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
*
* @summary Asynchronously creates a new event subscription or updates an existing event subscription based on the specified scope.
* x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForSubscription.json
*/
async function eventSubscriptionsCreateOrUpdateForSubscription() {
const subscriptionId =
process.env["EVENTGRID_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4";
const eventSubscriptionName = "examplesubscription3";
const eventSubscriptionInfo = {
destination: {
endpointType: "WebHook",
endpointUrl: "https://requestb.in/15ksip71",
},
filter: { isSubjectCaseSensitive: false },
};
const credential = new DefaultAzureCredential();
const client = new EventGridManagementClient(credential, subscriptionId);
const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
scope,
eventSubscriptionName,
eventSubscriptionInfo
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.EventGrid;
using Azure.ResourceManager.EventGrid.Models;
// Generated from example definition: specification/eventgrid/resource-manager/Microsoft.EventGrid/stable/2022-06-15/examples/EventSubscriptions_CreateOrUpdateForSubscription.json
// this example is just showing the usage of "EventSubscriptions_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ArmResource created on azure
// for more information of creating ArmResource, please refer to the document of ArmResource
// get the collection of this EventSubscriptionResource
string scope = "subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4";
ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope));
EventSubscriptionCollection collection = client.GetEventSubscriptions(scopeId);
// invoke the operation
string eventSubscriptionName = "examplesubscription3";
EventGridSubscriptionData data = new EventGridSubscriptionData()
{
Destination = new WebHookEventSubscriptionDestination()
{
Endpoint = new Uri("https://requestb.in/15ksip71"),
},
Filter = new EventSubscriptionFilter()
{
IsSubjectCaseSensitive = false,
},
};
ArmOperation<EventSubscriptionResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, eventSubscriptionName, data);
EventSubscriptionResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventGridSubscriptionData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"properties": {
"destination": {
"properties": {
"endpointBaseUrl": "https://requestb.in/15ksip71"
},
"endpointType": "WebHook"
},
"filter": {
"isSubjectCaseSensitive": false,
"subjectBeginsWith": "",
"subjectEndsWith": ""
},
"provisioningState": "Succeeded",
"topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4"
},
"id": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/providers/Microsoft.EventGrid/eventSubscriptions/examplesubscription3",
"name": "examplesubscription3",
"type": "Microsoft.EventGrid/eventSubscriptions"
}
Definitions
AzureFunctionEventSubscriptionDestination
Information about the azure function destination for an event subscription.
Name |
Type |
Default value |
Description |
endpointType
|
string:
AzureFunction
|
|
Type of the endpoint for the event subscription destination.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
|
Delivery attribute details.
|
properties.maxEventsPerBatch
|
integer
|
1
|
Maximum number of events per batch.
|
properties.preferredBatchSizeInKilobytes
|
integer
|
64
|
Preferred batch size in Kilobytes.
|
properties.resourceId
|
string
|
|
The Azure Resource Id that represents the endpoint of the Azure Function destination of an event subscription.
|
BoolEqualsAdvancedFilter
BoolEquals Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
BoolEquals
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
value
|
boolean
|
The boolean filter value.
|
createdByType
The type of identity that created the resource.
Name |
Type |
Description |
Application
|
string
|
|
Key
|
string
|
|
ManagedIdentity
|
string
|
|
User
|
string
|
|
DeadLetterWithResourceIdentity
Information about the deadletter destination with resource identity.
Name |
Type |
Description |
deadLetterDestination
|
DeadLetterDestination:
StorageBlobDeadLetterDestination
|
Information about the destination where events have to be delivered for the event subscription.
Uses the managed identity setup on the parent resource (namely, topic or domain) to acquire the authentication tokens being used during delivery / dead-lettering.
|
identity
|
EventSubscriptionIdentity
|
The identity to use when dead-lettering events.
|
DeliveryWithResourceIdentity
Information about the delivery for an event subscription with resource identity.
Name |
Type |
Description |
destination
|
EventSubscriptionDestination:
|
Information about the destination where events have to be delivered for the event subscription.
Uses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering.
|
identity
|
EventSubscriptionIdentity
|
The identity to use when delivering events.
|
DynamicDeliveryAttributeMapping
Dynamic delivery attribute mapping details.
Name |
Type |
Description |
name
|
string
|
Name of the delivery attribute or header.
|
properties.sourceField
|
string
|
JSON path in the event which contains attribute value.
|
type
|
string:
Dynamic
|
Type of the delivery attribute or header name.
|
EventDeliverySchema
The event delivery schema for the event subscription.
Name |
Type |
Description |
CloudEventSchemaV1_0
|
string
|
|
CustomInputSchema
|
string
|
|
EventGridSchema
|
string
|
|
EventHubEventSubscriptionDestination
Information about the event hub destination for an event subscription.
Name |
Type |
Description |
endpointType
|
string:
EventHub
|
Type of the endpoint for the event subscription destination.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
Delivery attribute details.
|
properties.resourceId
|
string
|
The Azure Resource Id that represents the endpoint of an Event Hub destination of an event subscription.
|
EventSubscription
Event Subscription
Name |
Type |
Default value |
Description |
id
|
string
|
|
Fully qualified identifier of the resource.
|
name
|
string
|
|
Name of the resource.
|
properties.deadLetterDestination
|
DeadLetterDestination:
StorageBlobDeadLetterDestination
|
|
The dead letter destination of the event subscription. Any event that cannot be delivered to its' destination is sent to the dead letter destination.
Uses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.deadLetterWithResourceIdentity
|
DeadLetterWithResourceIdentity
|
|
The dead letter destination of the event subscription. Any event that cannot be delivered to its' destination is sent to the dead letter destination.
Uses the managed identity setup on the parent resource (namely, topic or domain) to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.deliveryWithResourceIdentity
|
DeliveryWithResourceIdentity
|
|
Information about the destination where events have to be delivered for the event subscription.
Uses the managed identity setup on the parent resource (namely, topic or domain) to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.destination
|
EventSubscriptionDestination:
|
|
Information about the destination where events have to be delivered for the event subscription.
Uses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering.
|
properties.eventDeliverySchema
|
EventDeliverySchema
|
EventGridSchema
|
The event delivery schema for the event subscription.
|
properties.expirationTimeUtc
|
string
|
|
Expiration time of the event subscription.
|
properties.filter
|
EventSubscriptionFilter
|
|
Information about the filter for the event subscription.
|
properties.labels
|
string[]
|
|
List of user defined labels.
|
properties.provisioningState
|
EventSubscriptionProvisioningState
|
|
Provisioning state of the event subscription.
|
properties.retryPolicy
|
RetryPolicy
|
|
The retry policy for events. This can be used to configure maximum number of delivery attempts and time to live for events.
|
properties.topic
|
string
|
|
Name of the topic of the event subscription.
|
systemData
|
systemData
|
|
The system metadata relating to Event Subscription resource.
|
type
|
string
|
|
Type of the resource.
|
EventSubscriptionFilter
Filter for the Event Subscription.
Name |
Type |
Default value |
Description |
advancedFilters
|
AdvancedFilter[]:
|
|
An array of advanced filters that are used for filtering event subscriptions.
|
enableAdvancedFilteringOnArrays
|
boolean
|
|
Allows advanced filters to be evaluated against an array of values instead of expecting a singular value.
|
includedEventTypes
|
string[]
|
|
A list of applicable event types that need to be part of the event subscription. If it is desired to subscribe to all default event types, set the IncludedEventTypes to null.
|
isSubjectCaseSensitive
|
boolean
|
False
|
Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the filter
should be compared in a case sensitive manner.
|
subjectBeginsWith
|
string
|
|
An optional string to filter events for an event subscription based on a resource path prefix.
The format of this depends on the publisher of the events.
Wildcard characters are not supported in this path.
|
subjectEndsWith
|
string
|
|
An optional string to filter events for an event subscription based on a resource path suffix.
Wildcard characters are not supported in this path.
|
EventSubscriptionIdentity
The identity information with the event subscription.
Name |
Type |
Description |
type
|
EventSubscriptionIdentityType
|
The type of managed identity used. The type 'SystemAssigned, UserAssigned' includes both an implicitly created identity and a set of user-assigned identities. The type 'None' will remove any identity.
|
userAssignedIdentity
|
string
|
The user identity associated with the resource.
|
EventSubscriptionIdentityType
The type of managed identity used. The type 'SystemAssigned, UserAssigned' includes both an implicitly created identity and a set of user-assigned identities. The type 'None' will remove any identity.
Name |
Type |
Description |
SystemAssigned
|
string
|
|
UserAssigned
|
string
|
|
EventSubscriptionProvisioningState
Provisioning state of the event subscription.
Name |
Type |
Description |
AwaitingManualAction
|
string
|
|
Canceled
|
string
|
|
Creating
|
string
|
|
Deleting
|
string
|
|
Failed
|
string
|
|
Succeeded
|
string
|
|
Updating
|
string
|
|
HybridConnectionEventSubscriptionDestination
Information about the HybridConnection destination for an event subscription.
Name |
Type |
Description |
endpointType
|
string:
HybridConnection
|
Type of the endpoint for the event subscription destination.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
Delivery attribute details.
|
properties.resourceId
|
string
|
The Azure Resource ID of an hybrid connection that is the destination of an event subscription.
|
IsNotNullAdvancedFilter
IsNotNull Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
IsNotNull
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
IsNullOrUndefinedAdvancedFilter
IsNullOrUndefined Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
IsNullOrUndefined
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
NumberGreaterThanAdvancedFilter
NumberGreaterThan Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberGreaterThan
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
value
|
number
|
The filter value.
|
NumberGreaterThanOrEqualsAdvancedFilter
NumberGreaterThanOrEquals Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberGreaterThanOrEquals
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
value
|
number
|
The filter value.
|
NumberInAdvancedFilter
NumberIn Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberIn
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
number[]
|
The set of filter values.
|
NumberInRangeAdvancedFilter
NumberInRange Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberInRange
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
number[]
|
The set of filter values.
|
NumberLessThanAdvancedFilter
NumberLessThan Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberLessThan
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
value
|
number
|
The filter value.
|
NumberLessThanOrEqualsAdvancedFilter
NumberLessThanOrEquals Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberLessThanOrEquals
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
value
|
number
|
The filter value.
|
NumberNotInAdvancedFilter
NumberNotIn Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberNotIn
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
number[]
|
The set of filter values.
|
NumberNotInRangeAdvancedFilter
NumberNotInRange Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
NumberNotInRange
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
number[]
|
The set of filter values.
|
RetryPolicy
Information about the retry policy for an event subscription.
Name |
Type |
Default value |
Description |
eventTimeToLiveInMinutes
|
integer
|
1440
|
Time To Live (in minutes) for events.
|
maxDeliveryAttempts
|
integer
|
30
|
Maximum number of delivery retry attempts for events.
|
ServiceBusQueueEventSubscriptionDestination
Information about the service bus destination for an event subscription.
Name |
Type |
Description |
endpointType
|
string:
ServiceBusQueue
|
Type of the endpoint for the event subscription destination.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
Delivery attribute details.
|
properties.resourceId
|
string
|
The Azure Resource Id that represents the endpoint of the Service Bus destination of an event subscription.
|
ServiceBusTopicEventSubscriptionDestination
Information about the service bus topic destination for an event subscription.
Name |
Type |
Description |
endpointType
|
string:
ServiceBusTopic
|
Type of the endpoint for the event subscription destination.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
Delivery attribute details.
|
properties.resourceId
|
string
|
The Azure Resource Id that represents the endpoint of the Service Bus Topic destination of an event subscription.
|
StaticDeliveryAttributeMapping
Static delivery attribute mapping details.
Name |
Type |
Default value |
Description |
name
|
string
|
|
Name of the delivery attribute or header.
|
properties.isSecret
|
boolean
|
False
|
Boolean flag to tell if the attribute contains sensitive information .
|
properties.value
|
string
|
|
Value of the delivery attribute.
|
type
|
string:
Static
|
|
Type of the delivery attribute or header name.
|
StorageBlobDeadLetterDestination
Information about the storage blob based dead letter destination.
Name |
Type |
Description |
endpointType
|
string:
StorageBlob
|
Type of the endpoint for the dead letter destination
|
properties.blobContainerName
|
string
|
The name of the Storage blob container that is the destination of the deadletter events
|
properties.resourceId
|
string
|
The Azure Resource ID of the storage account that is the destination of the deadletter events
|
StorageQueueEventSubscriptionDestination
Information about the storage queue destination for an event subscription.
Name |
Type |
Description |
endpointType
|
string:
StorageQueue
|
Type of the endpoint for the event subscription destination.
|
properties.queueMessageTimeToLiveInSeconds
|
integer
|
Storage queue message time to live in seconds.
|
properties.queueName
|
string
|
The name of the Storage queue under a storage account that is the destination of an event subscription.
|
properties.resourceId
|
string
|
The Azure Resource ID of the storage account that contains the queue that is the destination of an event subscription.
|
StringBeginsWithAdvancedFilter
StringBeginsWith Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringBeginsWith
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringContainsAdvancedFilter
StringContains Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringContains
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringEndsWithAdvancedFilter
StringEndsWith Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringEndsWith
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringInAdvancedFilter
StringIn Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringIn
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringNotBeginsWithAdvancedFilter
StringNotBeginsWith Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringNotBeginsWith
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringNotContainsAdvancedFilter
StringNotContains Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringNotContains
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringNotEndsWithAdvancedFilter
StringNotEndsWith Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringNotEndsWith
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
StringNotInAdvancedFilter
StringNotIn Advanced Filter.
Name |
Type |
Description |
key
|
string
|
The field/property in the event based on which you want to filter.
|
operatorType
|
string:
StringNotIn
|
The operator type used for filtering, e.g., NumberIn, StringContains, BoolEquals and others.
|
values
|
string[]
|
The set of filter values.
|
systemData
Metadata pertaining to creation and last modification of the resource.
Name |
Type |
Description |
createdAt
|
string
|
The timestamp of resource creation (UTC).
|
createdBy
|
string
|
The identity that created the resource.
|
createdByType
|
createdByType
|
The type of identity that created the resource.
|
lastModifiedAt
|
string
|
The timestamp of resource last modification (UTC)
|
lastModifiedBy
|
string
|
The identity that last modified the resource.
|
lastModifiedByType
|
createdByType
|
The type of identity that last modified the resource.
|
WebHookEventSubscriptionDestination
Information about the webhook destination for an event subscription.
Name |
Type |
Default value |
Description |
endpointType
|
string:
WebHook
|
|
Type of the endpoint for the event subscription destination.
|
properties.azureActiveDirectoryApplicationIdOrUri
|
string
|
|
The Azure Active Directory Application ID or URI to get the access token that will be included as the bearer token in delivery requests.
|
properties.azureActiveDirectoryTenantId
|
string
|
|
The Azure Active Directory Tenant ID to get the access token that will be included as the bearer token in delivery requests.
|
properties.deliveryAttributeMappings
|
DeliveryAttributeMapping[]:
|
|
Delivery attribute details.
|
properties.endpointBaseUrl
|
string
|
|
The base URL that represents the endpoint of the destination of an event subscription.
|
properties.endpointUrl
|
string
|
|
The URL that represents the endpoint of the destination of an event subscription.
|
properties.maxEventsPerBatch
|
integer
|
1
|
Maximum number of events per batch.
|
properties.preferredBatchSizeInKilobytes
|
integer
|
64
|
Preferred batch size in Kilobytes.
|