Search code examples
c#office365subscriptionoutlook-restapi

Subscribe to Outlook/Office 365 API Status Code NotFound in C#


I am getting an issue when creating subscription. My steps are:

  1. Register app at https://apps.dev.microsoft.com
  2. Update permissions Read Mail and User's info
  3. Then update code, do same steps at https://learn.microsoft.com/en-us/outlook/rest/dotnet-tutorial
  4. After login, I can get access token Screen after login

  5. Then I try to create a subscription for Inbox

    var newSub = new Subscription
    {
        Resource = "me/mailFolders{'Inbox'}/messages",
        ChangeType = "created,updated",
        NotificationUrl = notificationUrl,
        ClientState = clientState,
        ExpirationDateTime = DateTime.Now.AddMinutes(15)
    };
    var result = await graphClient.Subscriptions.Request().AddAsync(newSub);
    
  6. Implement for notification in notification URL - I can get validation token and return in plain text.

    public async Task<ActionResult> Listen()
    {
        if (Request.QueryString["validationToken"] != null)
        {
            var token = Request.QueryString["validationToken"];
            return Content(token, "plain/text");
        }
    }
    
  7. But I always get this error.

image description here

Is there anyone know problem?


Solution

  • You must expose a public HTTPS endpoint to create a subscription and receive notifications from Microsoft Graph.