How to authenticate and create a Push notification Subscription to get Outlook email @mentions?










0















I am trying to authenticate in order to use Outlook REST API to subscription to Outlook emails via Push Subscription. I am using this documentation for reference: https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations



I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Office 365 Exchange Online" api.



Grant Required permission of Read user mail Screenshot



I am using the following code to get a Bearer token using "Microsoft.Identity.Client" nuget package. But I am still not able to subscribe to the Outlook Push Notification REST API and I am getting 401 Unauthorized error.



 static async Task<AuthenticationResult> AuthorizeAsync(string clientId)
{
var authority = $"https://login.microsoftonline.com/tenantName.onmicrosoft.com";
var app = new PublicClientApplication(clientId, authority);
string scopes = new string "Mail.Read" ;
var accounts = await app.GetAccountsAsync();

AuthenticationResult authenticationResult = null;
if (accounts.Any())

authenticationResult = await app.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());

else
{
try

var username = $"Environment.UserName@microsoft.com";
authenticationResult = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes, username);



Has anyone worked on a similar issue to authenticate and create a Push notification Subscription to get Outlook emails and can please help?










share|improve this question
























  • Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

    – Jeremy Thake MSFT
    Nov 20 '18 at 4:21











  • Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

    – Neha
    Dec 7 '18 at 0:40












  • Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

    – Neha
    Jan 2 at 15:36











  • unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

    – Jeremy Thake MSFT
    Jan 3 at 21:13











  • This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

    – Paul
    Jan 4 at 16:39















0















I am trying to authenticate in order to use Outlook REST API to subscription to Outlook emails via Push Subscription. I am using this documentation for reference: https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations



I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Office 365 Exchange Online" api.



Grant Required permission of Read user mail Screenshot



I am using the following code to get a Bearer token using "Microsoft.Identity.Client" nuget package. But I am still not able to subscribe to the Outlook Push Notification REST API and I am getting 401 Unauthorized error.



 static async Task<AuthenticationResult> AuthorizeAsync(string clientId)
{
var authority = $"https://login.microsoftonline.com/tenantName.onmicrosoft.com";
var app = new PublicClientApplication(clientId, authority);
string scopes = new string "Mail.Read" ;
var accounts = await app.GetAccountsAsync();

AuthenticationResult authenticationResult = null;
if (accounts.Any())

authenticationResult = await app.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());

else
{
try

var username = $"Environment.UserName@microsoft.com";
authenticationResult = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes, username);



Has anyone worked on a similar issue to authenticate and create a Push notification Subscription to get Outlook emails and can please help?










share|improve this question
























  • Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

    – Jeremy Thake MSFT
    Nov 20 '18 at 4:21











  • Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

    – Neha
    Dec 7 '18 at 0:40












  • Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

    – Neha
    Jan 2 at 15:36











  • unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

    – Jeremy Thake MSFT
    Jan 3 at 21:13











  • This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

    – Paul
    Jan 4 at 16:39













0












0








0








I am trying to authenticate in order to use Outlook REST API to subscription to Outlook emails via Push Subscription. I am using this documentation for reference: https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations



I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Office 365 Exchange Online" api.



Grant Required permission of Read user mail Screenshot



I am using the following code to get a Bearer token using "Microsoft.Identity.Client" nuget package. But I am still not able to subscribe to the Outlook Push Notification REST API and I am getting 401 Unauthorized error.



 static async Task<AuthenticationResult> AuthorizeAsync(string clientId)
{
var authority = $"https://login.microsoftonline.com/tenantName.onmicrosoft.com";
var app = new PublicClientApplication(clientId, authority);
string scopes = new string "Mail.Read" ;
var accounts = await app.GetAccountsAsync();

AuthenticationResult authenticationResult = null;
if (accounts.Any())

authenticationResult = await app.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());

else
{
try

var username = $"Environment.UserName@microsoft.com";
authenticationResult = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes, username);



Has anyone worked on a similar issue to authenticate and create a Push notification Subscription to get Outlook emails and can please help?










share|improve this question
















I am trying to authenticate in order to use Outlook REST API to subscription to Outlook emails via Push Subscription. I am using this documentation for reference: https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations



I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Office 365 Exchange Online" api.



Grant Required permission of Read user mail Screenshot



I am using the following code to get a Bearer token using "Microsoft.Identity.Client" nuget package. But I am still not able to subscribe to the Outlook Push Notification REST API and I am getting 401 Unauthorized error.



 static async Task<AuthenticationResult> AuthorizeAsync(string clientId)
{
var authority = $"https://login.microsoftonline.com/tenantName.onmicrosoft.com";
var app = new PublicClientApplication(clientId, authority);
string scopes = new string "Mail.Read" ;
var accounts = await app.GetAccountsAsync();

AuthenticationResult authenticationResult = null;
if (accounts.Any())

authenticationResult = await app.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());

else
{
try

var username = $"Environment.UserName@microsoft.com";
authenticationResult = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes, username);



Has anyone worked on a similar issue to authenticate and create a Push notification Subscription to get Outlook emails and can please help?







outlook microsoft-graph azure-ad-graph-api outlook-restapi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 21:33







Neha

















asked Nov 14 '18 at 7:38









NehaNeha

113




113












  • Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

    – Jeremy Thake MSFT
    Nov 20 '18 at 4:21











  • Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

    – Neha
    Dec 7 '18 at 0:40












  • Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

    – Neha
    Jan 2 at 15:36











  • unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

    – Jeremy Thake MSFT
    Jan 3 at 21:13











  • This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

    – Paul
    Jan 4 at 16:39

















  • Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

    – Jeremy Thake MSFT
    Nov 20 '18 at 4:21











  • Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

    – Neha
    Dec 7 '18 at 0:40












  • Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

    – Neha
    Jan 2 at 15:36











  • unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

    – Jeremy Thake MSFT
    Jan 3 at 21:13











  • This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

    – Paul
    Jan 4 at 16:39
















Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

– Jeremy Thake MSFT
Nov 20 '18 at 4:21





Is there any reason you are using the Outlook Rest API rather than the Microsoft Graph? Plenty more samples there github.com/microsoftgraph/aspnet-webhooks-rest-sample and a hands on lab too github.com/microsoftgraph/…

– Jeremy Thake MSFT
Nov 20 '18 at 4:21













Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

– Neha
Dec 7 '18 at 0:40






Hi Jeremy, currently I am using the Microsoft Graph after your reply. t.But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error. Can you please help. I have posted link to my question here: stackoverflow.com/questions/53661716/…

– Neha
Dec 7 '18 at 0:40














Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

– Neha
Jan 2 at 15:36





Hi JeremyThakeMSFT, I was able to successfully create a subscription using ngrok for notification url. But this subscription is for notifying all the emails and not just @mentions. Is there a way to to filter only mentions in the email? Thank you

– Neha
Jan 2 at 15:36













unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

– Jeremy Thake MSFT
Jan 3 at 21:13





unfortunately not. The subscription allows you to subscribe to all activity in the users inbox. From there you can inspect each message to see whether there are mentions in it. This is actually a neat request, if you could request it on UserVoice i'll talk to the PMs about this becoming a feature officespdev.uservoice.com/forums/…

– Jeremy Thake MSFT
Jan 3 at 21:13













This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

– Paul
Jan 4 at 16:39





This would be very helpful. Also, it looks like there already is a uservoice request for $filter support with webhook subscriptions here: officespdev.uservoice.com/forums/…

– Paul
Jan 4 at 16:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295166%2fhow-to-authenticate-and-create-a-push-notification-subscription-to-get-outlook-e%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295166%2fhow-to-authenticate-and-create-a-push-notification-subscription-to-get-outlook-e%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo