title: 400 Bad request error on using Microsoft Graph API to subscribe to Outlook Push Notifications
body: <p>I am trying to create a subscription to get Outlook emails @mentions via Push Notification using Microsoft Graph API. I am using <a href="https://docs.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0#notification-endpoint-validation" rel="nofollow noreferrer">this documentation</a> for reference/</p>
  
  <p>I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Microsoft Graph" API and admin consented it through Microsoft Demo tenant. But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting <code>400 Bad Request</code> error.</p>
  
  <p>I also tried granting all permissions to the app in portal.azure.com under the Microsoft Graph API and again admin consented it through my Microsoft demo tenant but I am still getting same <code>400</code> bad request error.</p>
  
  <p>I am using the following code to create a subscription:</p>
  
  <pre><code>private static void Subscribe(AuthenticationHeaderValue authHeader) 
  {
      using(HttpClient _httpClient = new HttpClient()) 
      {
         _httpClient.BaseAddress = new Uri("https://graph.microsoft.com");
         _httpClient.DefaultRequestHeaders.Accept.Clear();
         _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
         _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
         _httpClient.DefaultRequestHeaders.Authorization = authHeader;
  
         // connect to the REST endpoint to subscribe   
         var json = @"{
                         'changetype':'created,updated',
                         'notificationurl': 'http://requestbin.fullcontact.com/two54stw/',
                         'resource': 'me/mailfolder(\'Inbox\')/messages',
                         'clientstate': 'secretclientvalue'
                     }";
  
         HttpContent contentPost = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
         HttpResponseMessage subscribe = _httpClient.PostAsync($"v1.0/subscriptions", contentPost).Result;
         Console.WriteLine("New subscription created!");
      }
  }
  </code></pre>
  
  <p>Has anyone worked on a similar issue to create a Push notification Subscription to get Outlook emails and can please help?</p>