0
votes

I have created event grid topic inside event grid domain. Now I want to create event subscription for that topic using rest api.

I have read docs through this link

https://docs.microsoft.com/en-us/rest/api/eventgrid/eventsubscriptions/createorupdate?source=docs#uri-parameters.

But I am not able to find url for what I need.

I have tried this url.

https://management.azure.com/subscriptions/{subscription ID}/resourceGroups/{resourse group name}/providers/Microsoft.EventGrid/domains/{event grid domain name}/topics/{topic name}/providers/Microsoft.EventGrid/eventSubscriptions/{event subscription name}?api-version=2019-02-01-preview

2

2 Answers

1
votes

The domain topic can be created using the following APIs:

  1. Domain Topics - Create Or Update

    for example:

    https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRG/providers/Microsoft.EventGrid/domains/myDomain/topics/myTopicXXX?api-version=2020-01-01-preview
    

    the payload is empty: {}

  2. Event Subscriptions - Create Or Update

    for example:

    https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRG/providers/Microsoft.EventGrid/domains/myDomain/topics/myTopic/providers/Microsoft.EventGrid/eventSubscriptions/mySubscription?api-version=2020-01-01-preview
    

Example of the payload:

    {
      "properties":{
       "destination":{
          "endpointType":"HybridConnection",
          "properties":{
            "resourceId":"<myHybridConnectionresourceId>"
          }
        },
        "filter":{
        "isSubjectCaseSensitive":false,
        "subjectBeginsWith":null,
        "subjectEndsWith":null
        },
        "labels":[],
        "eventDeliverySchema":"EventGridSchema",
        "retryPolicy":{
          "maxDeliveryAttempts":3,
          "eventTimeToLiveInMinutes":1440
         }
      }
    }

In this case, the domain topic will be created automatically when doesn't exist it. Note, that this is a great feature allows to create a topic from the subscriber side.

Btw. have a look at my Azure Event Grid Tools, it is built on the REST APIs.

0
votes

It seems that there is no way to create event subscription in domain topic with rest api. Workaroud: you could use Azure CLI or powershell to achieve it.

The Event Grid service automatically creates and manages the corresponding topic in a domain based on the call to create an event subscription for a domain topic. Similarly, when the last event subscription for a topic is deleted, the topic is deleted as well.

Subscribing to a topic in a domain is the same as subscribing to any other Azure resource. For the source resource ID, specify the event domain ID returned when creating the domain earlier. To specify the topic you want to subscribe to, add /topics/<my-topic> to the end of the source resource ID.

az eventgrid event-subscription create \
  --name <event-subscription> \
  --source-resource-id "/subscriptions/<sub-id>/resourceGroups/<my-resource-group>/providers/Microsoft.EventGrid/domains/<my-domain-name>/topics/demotopic1" \
  --endpoint https://contoso.azurewebsites.net/api/updates