I am using PowerShell to subscribe Graph notification with rich (resource) data, but the response doesn't contains the field that I need

HGZL (Nick Hongzheng Li) 20 Reputation points
2024-03-26T07:44:21.51+00:00

I am using below PS command to subscribe Graph with resource data (email unique id and email subject)

New-MgSubscription -ChangeType "created" `
-NotificationUrl "https://******.azurewebsites.net/api/webhook" `
-ExpirationDateTime (Get-Date).AddMinutes(4000) `
-ClientState "secretClientValue" `
-Resource '/users/user@example.com/mailfolders/mailfolderId/messages?$select=id,subject'`
-IncludeResourceData `
-EncryptionCertificate "Base64encodePublicKey" `
-EncryptionCertificateId "https://****cert.vault.azure.net/certificates/cert****"


The expect response from Graph is contains the email ID and subject

But when I decrypt the response data, I can only get the JSON which contains subject only, I need email ID as well.

{"subject":"RE: TestEmail"}


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,282 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft Vendor
    2024-05-25T11:14:40.0333333+00:00

    Hi HGZL (Nick Hongzheng Li)

    Thanks for reaching out.

    When you create a subscription in order to get resource data (rich notification), You will get the resource data in the field called encryptedContent.

    In order to get the resource id, which in your case is message Id. You need to read resource field as well from the notification object.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.