Home > front end >  Subscription made but zero events received
Subscription made but zero events received

Time:11-11

Created a subscription to a mailbox but events are not fired when mails are received on the mailbox. Is the Graph mail subscription feature not very repayable?

I did this exact thing a couple of weeks ago in prototype codebase and it worked perfectly. Now I'm implementing in production code and it no longer seems to work.

GraphServiceClient graphClient = CreateGraphClient();

var subscription = new Subscription()
{
    ChangeType = "created",
    NotificationUrl = callbackUrl,
    Resource = string.Format("/users/{0}/mailFolders/inbox/messages", mailAccount),
    ClientState = Guid.NewGuid().ToString(),
    ExpirationDateTime = DateTime.UtcNow.AddMinutes(4230),
};

var result = graphClient.Subscriptions.Request().AddAsync(subscription).Result;

No exception is thrown and we register that the initial call to the NotificationUrl is actually performed.

What is going on??!?

CodePudding user response:

Found the error. I put a ([FromQuery] string validationToken) on the Post function.

This means that if a client is calling this Post function without a validationToken parameter they will get an error before the code is even reached.

Either set a default value of null on the parameter or do not add a parameter to the function definition and just read the query string from code instead.

public IActionResult Post([FromQuery] string? validationToken = null)
  • Related