title: App-Only Token Fetches Users But Can't Create Subscriptions?
body: <p>I am using an "app-only" token to retrieve my users which works just fine.</p>
  
  <p>Once the app loops through the users, it's supposed to create a subscription as shown below.</p>
  
  <p>However, when attempting to create the subscription, the request simply returns: </p>
  
  <blockquote>
    <p>Code: InvalidRequest Message: Unable to connect to the remote server</p>
    
    <p>Inner error</p>
  </blockquote>
  
  <p><strong>My question is, why does the subscription request fail to connect</strong> when I am obviously able to successfully connect in the first request which retrieves the users?</p>
  
  <p>How can I see the inner error?</p>
  
  <pre><code>string tenantId = appSettings.TenantId;
  
  var client = sdkHelper.GetAuthenticatedClientAppOnly(tenantId);
  
  // this request works...
  IGraphServiceUsersCollectionPage users = await client.Users.Request().Filter("userPrincipalName eq 'MY_USER_PRINCIPAL_NAME'").GetAsync();
  
  if (users?.Count &gt; 0)
  {
      foreach (User user in users)
      {
          // this request doesn't work...
          Subscription newSubscription = new Subscription();
          string clientState = Guid.NewGuid().ToString();
          newSubscription = await client.Subscriptions.Request().AddAsync(new Subscription
          {
              Resource = $"users/{ user.Id }@{ tenantId }/mailFolders('Inbox')/messages",
              //Resource = $"users/{ user.UserPrincipalName }/mailFolders('Inbox')/messages", // also tried using email address
              ChangeType = "created",
              NotificationUrl = "https://localhost:44334/notification/listen",
              ClientState = clientState,
              //ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 4230, 0) // current maximum lifespan for messages
              ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 15, 0)     // shorter duration useful for testing
          });
      }
  }
  </code></pre>
  
  <p>When I wrap the call in a try/catch, the error message is just this with no inner exception:</p>
  
  <blockquote>
    <p>Exception of type 'Microsoft.Graph.ServiceException' was thrown.</p>
  </blockquote>
  
  <p>I have tried all three resources URLs but all result in the same error as shown above:</p>
  
  <ul>
  <li>Resource = <code>$"users/{ user.Id }/mailFolders('Inbox')/messages",</code></li>
  <li>Resource = <code>$"users/{ user.Id }@{ tenantId }/mailFolders('Inbox')/messages",</code></li>
  <li>Resource = <code>$"users/{ user.UserPrincipalName }/mailFolders('Inbox')/messages",</code></li>
  </ul>
  
  <p>I found this thread on github but the requests don't seem to work for me.</p>
  
  <ol>
  <li>Allow Application-Only requests to create subscriptions - <a href="https://github.com/microsoftgraph/microsoft-graph-docs/issues/238" rel="nofollow noreferrer">https://github.com/microsoftgraph/microsoft-graph-docs/issues/238</a></li>
  </ol>