Calling Microsoft Graph API from Azure Function to retrieve user's Contacts












-1















I cannot find a good working sample that calls the Graph API and retrieves the user's contacts from within an Azure Function. Part of the issue is a lack of documentation and samples as this seems new-ish. Is this even possible? I am trying to create a function that can take a phone number and check against the user's contacts to see if the contact exists. So far, the only way I can achieve authentication is to use Postman to retrieve a token manually. That token didn't even work to retrieve the contacts. I know I am doing something wrong but I think what I really need is the big picture. I'm missing something. Thank you for your help.










share|improve this question



























    -1















    I cannot find a good working sample that calls the Graph API and retrieves the user's contacts from within an Azure Function. Part of the issue is a lack of documentation and samples as this seems new-ish. Is this even possible? I am trying to create a function that can take a phone number and check against the user's contacts to see if the contact exists. So far, the only way I can achieve authentication is to use Postman to retrieve a token manually. That token didn't even work to retrieve the contacts. I know I am doing something wrong but I think what I really need is the big picture. I'm missing something. Thank you for your help.










    share|improve this question

























      -1












      -1








      -1


      1






      I cannot find a good working sample that calls the Graph API and retrieves the user's contacts from within an Azure Function. Part of the issue is a lack of documentation and samples as this seems new-ish. Is this even possible? I am trying to create a function that can take a phone number and check against the user's contacts to see if the contact exists. So far, the only way I can achieve authentication is to use Postman to retrieve a token manually. That token didn't even work to retrieve the contacts. I know I am doing something wrong but I think what I really need is the big picture. I'm missing something. Thank you for your help.










      share|improve this question














      I cannot find a good working sample that calls the Graph API and retrieves the user's contacts from within an Azure Function. Part of the issue is a lack of documentation and samples as this seems new-ish. Is this even possible? I am trying to create a function that can take a phone number and check against the user's contacts to see if the contact exists. So far, the only way I can achieve authentication is to use Postman to retrieve a token manually. That token didn't even work to retrieve the contacts. I know I am doing something wrong but I think what I really need is the big picture. I'm missing something. Thank you for your help.







      microsoft-graph azure-functions






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 16:58









      ToddTodd

      11618




      11618
























          1 Answer
          1






          active

          oldest

          votes


















          2














          The auth token binding may help at least with the act of getting the token. In this case, if it's on behalf of the user invoking the function, you'll want to use the identity: userFromRequest setup. Keep in mind that for debugging, you'd still have to acquire a user token for the app and attach that to calls to your function, but you can use the function app's /.auth/login/aad and /.auth/me endpoints for that.



          Make sure that your application registration has the Contacts.Read permission. This is required for the contacts API.Today, the UX for App Service Authentication / Authorization today links to the existing permissions UX, which unfortunately uses different names for things. I'd recommend navigating directly to the AAD section of the portal and selecting App registrations (Preview). Find your app registration there (defaults to same as your app name), and browse through the API permissions there. That way the right names show up and will match the Graph docs.






          share|improve this answer
























          • I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

            – Todd
            Nov 16 '18 at 1:37











          • I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

            – Todd
            Nov 23 '18 at 15:44











          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%2f53324443%2fcalling-microsoft-graph-api-from-azure-function-to-retrieve-users-contacts%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The auth token binding may help at least with the act of getting the token. In this case, if it's on behalf of the user invoking the function, you'll want to use the identity: userFromRequest setup. Keep in mind that for debugging, you'd still have to acquire a user token for the app and attach that to calls to your function, but you can use the function app's /.auth/login/aad and /.auth/me endpoints for that.



          Make sure that your application registration has the Contacts.Read permission. This is required for the contacts API.Today, the UX for App Service Authentication / Authorization today links to the existing permissions UX, which unfortunately uses different names for things. I'd recommend navigating directly to the AAD section of the portal and selecting App registrations (Preview). Find your app registration there (defaults to same as your app name), and browse through the API permissions there. That way the right names show up and will match the Graph docs.






          share|improve this answer
























          • I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

            – Todd
            Nov 16 '18 at 1:37











          • I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

            – Todd
            Nov 23 '18 at 15:44
















          2














          The auth token binding may help at least with the act of getting the token. In this case, if it's on behalf of the user invoking the function, you'll want to use the identity: userFromRequest setup. Keep in mind that for debugging, you'd still have to acquire a user token for the app and attach that to calls to your function, but you can use the function app's /.auth/login/aad and /.auth/me endpoints for that.



          Make sure that your application registration has the Contacts.Read permission. This is required for the contacts API.Today, the UX for App Service Authentication / Authorization today links to the existing permissions UX, which unfortunately uses different names for things. I'd recommend navigating directly to the AAD section of the portal and selecting App registrations (Preview). Find your app registration there (defaults to same as your app name), and browse through the API permissions there. That way the right names show up and will match the Graph docs.






          share|improve this answer
























          • I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

            – Todd
            Nov 16 '18 at 1:37











          • I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

            – Todd
            Nov 23 '18 at 15:44














          2












          2








          2







          The auth token binding may help at least with the act of getting the token. In this case, if it's on behalf of the user invoking the function, you'll want to use the identity: userFromRequest setup. Keep in mind that for debugging, you'd still have to acquire a user token for the app and attach that to calls to your function, but you can use the function app's /.auth/login/aad and /.auth/me endpoints for that.



          Make sure that your application registration has the Contacts.Read permission. This is required for the contacts API.Today, the UX for App Service Authentication / Authorization today links to the existing permissions UX, which unfortunately uses different names for things. I'd recommend navigating directly to the AAD section of the portal and selecting App registrations (Preview). Find your app registration there (defaults to same as your app name), and browse through the API permissions there. That way the right names show up and will match the Graph docs.






          share|improve this answer













          The auth token binding may help at least with the act of getting the token. In this case, if it's on behalf of the user invoking the function, you'll want to use the identity: userFromRequest setup. Keep in mind that for debugging, you'd still have to acquire a user token for the app and attach that to calls to your function, but you can use the function app's /.auth/login/aad and /.auth/me endpoints for that.



          Make sure that your application registration has the Contacts.Read permission. This is required for the contacts API.Today, the UX for App Service Authentication / Authorization today links to the existing permissions UX, which unfortunately uses different names for things. I'd recommend navigating directly to the AAD section of the portal and selecting App registrations (Preview). Find your app registration there (defaults to same as your app name), and browse through the API permissions there. That way the right names show up and will match the Graph docs.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 1:13









          mattchendersonmattchenderson

          1,51549




          1,51549













          • I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

            – Todd
            Nov 16 '18 at 1:37











          • I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

            – Todd
            Nov 23 '18 at 15:44



















          • I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

            – Todd
            Nov 16 '18 at 1:37











          • I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

            – Todd
            Nov 23 '18 at 15:44

















          I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

          – Todd
          Nov 16 '18 at 1:37





          I will give this a try and report back. There are so many outdated tutorials and none of which are exactly what I am trying to accomplish. The few that are close are off base in one way or another. I am going to try to get auth working first. You state that for testing I have to get the token. What happens in production? Is that somehow handled? If so, why can't I do the same thing during testing? Thanks for helping me clear this issue in my mind!!

          – Todd
          Nov 16 '18 at 1:37













          I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

          – Todd
          Nov 23 '18 at 15:44





          I was able to get this working by making explicit calls to the API to get a token and then programmatically use that token to retrieve results from the Graph. Thanks for your assistance!

          – Todd
          Nov 23 '18 at 15:44




















          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%2f53324443%2fcalling-microsoft-graph-api-from-azure-function-to-retrieve-users-contacts%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python