0

How can I only capture the change of a user email with the Partner Topic for Microsoft Graph API?

This article states that you can use custom data.key:

"For events in Cloud Events schema, use the following values for the key: eventid, source, eventtype, eventtypeversion, or event data (like data.key1)".

So do I add the key as data.state and value as *? I tried it and nothing gets returned. I want to capture the oldValue and newValue, is this something the partner topic cannot do?

enter image description here

1 Answers1

0

AFAIK and according to this MS document You can build a Graph API subscription with the following properties to leverage the Partner Topic for Microsoft Graph API to capture the change of a user email.

  • Below is the sample request provided in the mentioned MS document.

    POST to https://graph.microsoft.com/beta/subscriptions
    
      x-ms-enable-features: EventGrid
    
      Body:
      {
          "changeType": "Updated,Deleted,Created",
          "notificationUrl": "EventGrid:?azuresubscriptionid=8A8A8A8A-4B4B-4C4C-4D4D-12E12E12E12E&resourcegroup=yourResourceGroup&partnertopic=youPartnerTopic&location=theNameOfAzureRegionFortheTopic",
          "resource": "users",
          "expirationDateTime": "2022-04-30T00:00:00Z",
          "clientState": "mysecret"
      }
    
  • Note: Change the above values based on your requirement for example change type is Updated and Data.key1 should be set to UserPrincipalName, data.key2 to OldValue, and data.key3 to NewValue in the notificationUrl. The user's UserPrincipalName, the OldValue, and the NewValue are all provided in the event data when the user's email is modified.

  • Another option is to use an advanced filter with the "Data" column and the "CloudEvent" schema version as per this similar SO question.

vijaya
  • 1,525
  • 1
  • 2
  • 6
  • "*Data.key1 should be set to UserPrincipalName, data.key2 to OldValue, and data.key3 to NewValue in the notificationUrl.*" Sorry, do you mean to add them in the key field input that I provided in the image? Or do you mean in the field that you posted named _notificationUrl_, like: _EventGrid:?...?userPrincipalName,ldValue,...._ Because right now that will still bring all events correct? Can I not limit only email event changes in the "Filters" tab (in my image) when adding the Event Subscription to the partner topic in the Azure Portal? – AnalyzingTasks May 23 '23 at 22:03
  • @AnalyzingTasks Yes i mean in my posted notification URL. Edited the answer check once. Not sure about this but once try this in your image also like In the "Key" field, enter data.key1 (for UserPrincipalName). In the "Operator" field, select "StringEquals". In the "Value" field, enter the specific user principal name you want to capture email changes for. – vijaya May 24 '23 at 03:31
  • So should it be: EventGrid:?azuresubscriptionid=8A8A8A8A-4B4B-4C4C-4D4D-12E12E12E12E&resourcegroup=yourResourceGroup&partnertopic=youPartnerTopic&location=theNameOfAzureRegionFortheTopic?userPrincipalName,OldValue,NewValue ? But how does that tell the topic to filter email only? I know you can do it on the subscribing webhook, but I was under the impression that you could do it in advance in the event subscription setup (like Filters tab in image) so you didn't have to code that yourself in the webhook. Also I want to capture email changes for any user, not just a specific user. – AnalyzingTasks May 24 '23 at 14:32