0

I have defined a notification function to be suscribed to Graph:

public static class NotificationFunction
    {
        [FunctionName("NotificationFunction")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string validationToken = req.Query["validationToken"];

            log.LogInformation($"validationToken {validationToken}");    

            return new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(validationToken, System.Text.Encoding.UTF8, "text/plain")
            };
        }
    }

I try to add this notificationUrl in a Timer Function:

var subscription = new Subscription
            {
                ChangeType = "created,updated",
                NotificationUrl = NotificationUrlValue,
                Resource = "me/mailFolders('Inbox')/messages",
                ExpirationDateTime = DateTimeOffset.Parse("2019-12-30T18:23:45.9356913Z"),
                ClientState = "secretClientValue"
            };

The NotificationUrlValue is the NotificationFunction URL and works fine If I test it, but when the Timer Trigger runs gets:

Code: InvalidRequest
Message: Subscription validation request failed. Must respond with 200 OK to this request.

In the Trigger function Monitor I don't see any call, maybe is a firewall problem? From which IP is invoking the NotificationUrl?

felixmondelo
  • 1,324
  • 1
  • 10
  • 19
  • 1
    I use the same code you shared to make it work fine in Timer Trigger. Based on the error message, your NotificationUrlValue is not valid. How did you test the NotificationFunction URL? Or you could test `POST https://graph.microsoft.com/beta/subscriptions` in Microsoft Graph Explorer first to see if NotificationUrlValue is valid. – Allen Wu Dec 04 '19 at 09:36
  • You are correct, the NotificationUrl that I was using is behind a firewall, the good one is other url. Thanks. – felixmondelo Dec 04 '19 at 11:08
  • So the cause of the problem is the firewall, right? It seems that you have figured it out. Do you mind adding an answer about your solution to help others? – Allen Wu Dec 05 '19 at 01:37

1 Answers1

0

The problem was that the NotificationUrl was behind a firewall, solution is change the NotificationUrl to an accesible one.

felixmondelo
  • 1,324
  • 1
  • 10
  • 19