Configure Advanced Filters in Logic Apps using Event Grid

Cosmin Stirbu 151 Reputation points
2023-02-01T11:52:24.7033333+00:00

Hello,

I noticed that on the Event Grid connector you cannot configure Advanced Filters.

However you can manually go on the under the hood Event Grid System Topic -> Event Subscription and configure Advanced Filters there directly.

The issue with the above manual workaround is that if you disable the Logic App then the under the hood Event Grid System Topic + Event Subscription are deleted and when you enabled it again, a new Event Grid System Topic + Event Subscription is created, but without the Advanced Filters.

Is there a way to configure Advanced Filters that would "survive" across a disable&enable sequence of steps?

Thank you,

Cosmin

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,875 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
319 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Roman Kiss 2,246 Reputation points
    2023-02-03T16:44:39.2433333+00:00

    The following screen snippet shows my example of the Http Webhook trigger:

    User's image

    As you can see the above, the Http Webhook subscriber part is the REST PUT request to create the AEG Subscription with a dynamic CallbackUrl() function addressed to the next activity such as the Scope Subscriber.

    Note, when the Logic App is enabled, the Http Webhook is triggered to perform creating the AEG Subscription based on the REST PUT request declared by its subscriber included a validation of the event handler destination endpoint.

    The following is an example of the Subscribe-Body payload with the filter property:

    {
      "properties": {
        "destination": {
          "endpointType": "WebHook",
          "properties": {
            "endpointUrl": @{listCallbackUrl()}
          }
        },
        "filter": {
          "advancedFilters": [
            {
              "key": "data.make",
              "operatorType": "StringIn",
              "values": [
                "Ducati",
                "BMW"
              ]
            }
          ]
        }
      }
    }
    

    Thanks

    Roman

    0 comments No comments

  2. Nick W 0 Reputation points
    2023-06-08T03:09:53.72+00:00

    A simpler solution where you don't need to manage the auth is to just modify the object for the Event Trigger. Do note modifying via the UI will break this. (Use bicep to deploy)

    I also bumped the API version it used as some advanced filter props are newer

    "triggers": {
        "When_a_resource_event_occurs": {
            "inputs": {
                "body": {
                    "properties": {
                        "destination": {
                            "endpointType": "webhook",
                            "properties": {
                                "endpointUrl": "@{listCallbackUrl()}"
                            }
                        },
                        "filter": {
                            "includedEventTypes": [
                                "Microsoft.Storage.BlobCreated"
                            ],
                            "subjectEndsWith": ".txt",
                            "advancedFilters": [
                                {
                                  "key": "data.api",
                                  "operatorType": "StringIn",
                                  "values": ["FlushWithClose"]
                                }
                              ],
                              "enableAdvancedFilteringOnArrays": true
                        },
                        "topic": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}"
                    }
                },
                "host": {
                    "connection": {
                        "name": "@parameters('$connections')['azureeventgrid']['connectionId']"
                    }
                },
                "path": "/subscriptions/@{encodeURIComponent('{subscriptionId}')}/providers/@{encodeURIComponent('Microsoft.Storage.StorageAccounts')}/resource/eventSubscriptions",
                "queries": {
                    "x-ms-api-version": "2022-06-15"
                }
            },
            "splitOn": "@triggerBody()",
            "type": "ApiConnectionWebhook"
        }
    }
    

    https://learn.microsoft.com/en-us/azure/templates/microsoft.eventgrid/systemtopics/eventsubscriptions?tabs=bicep&pivots=deployment-language-bicep#advancedfilter-objects

    0 comments No comments