locked
Unable to call graph API from SharePoint page RRS feed

  • Question

  • I am trying to call the graph API for fetching user profile information.

    The blog post I followed is this

    My AAD app config is like:

    URL: https://tenant.sharepoint.com 
    Reply-url: https://tenant.sharepoint.com 
    Permissions: Graph API :: Read all users' full profiles

    However, I am getting an error of invalid reply url. Not sure what reply url is it trying to send the response to.
    • Edited by SharePointGuy Sunday, September 10, 2017 3:48 PM Formatting
    Sunday, September 10, 2017 3:47 PM

Answers

  • I was able to resolve this issue. So basically the issue was with the reply url wherein the Azure AD was trying to send the token back to 

     

    https://tenant.sharepoint.com/sites/mysite/SiteAssets/ADALTest.aspx

     

    and my reply-url's did not have that entry. I had only entered either my tenant url or site collection url. Added the full url and now works smoothly.

    • Proposed as answer by Dennis Guo Friday, September 15, 2017 10:12 AM
    • Marked as answer by SharePointGuy Friday, September 15, 2017 11:34 AM
    Friday, September 15, 2017 8:21 AM

All replies

  • Hi,

    If you want to get user profile information from SharePoint page, we can use SharePoint REST API and jQuery Ajax to achieve it.

    The following articles for your reference:

    SharePoint 2013: Get UserProfile Properties with REST API

    http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

    User profiles REST API reference

    https://msdn.microsoft.com/en-us/library/office/dn790354.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, September 11, 2017 7:04 AM
  • Thanks for your response. However, there are a few properties that I am unable to get in the UserProfile REST API like "Office Location" because this property is filled from a termset when users go ahead and update their locations. Unfortunately in my case, no users have populated that field and so is blank. Also I do not have EmpID peoperty available.
    Monday, September 11, 2017 8:18 AM
  • Hi,

    If you want get some custom user profile properties, we can use this:

    http://sp2013/sites/team/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=UserProfileProperties

    The following code for your reference and add the code into a script editor web part to check if it works.

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	$.ajax({
    		url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
    		headers: { Accept: "application/json;odata=verbose" },
    		success: function (data) {			
    			//Get properties from user profile Json response			
    			var properties = data.d.UserProfileProperties.results;
    			for (var i = 0; i < properties.length; i++) {
    				var property = properties[i];
    				if (property.Key == "EmpID") {
    					alert(property.Value);
    				}			
    			}
    		},
    		error: function (jQxhr, errorCode, errorThrown) {
    			alert(errorThrown);
    		}
    	}); 
    });
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    • Edited by Dennis Guo Monday, September 11, 2017 8:38 AM
    Monday, September 11, 2017 8:36 AM
  • Appreciate your quick response. However, EmpID is missing altogether from my response. I can see that this property is there in my AAD profile. Is there a way to sync that property?

    Any leads for the location property? As far as I know, I cannot sync that property to SharePoint User Profile.

    Monday, September 11, 2017 8:46 AM
  • Hi,

    Please check the user properties in Admin center.

    More information:

    https://msdn.microsoft.com/en-us/pnp_articles/bulk-user-profile-update-api-for-sharepoint-online

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, September 11, 2017 9:10 AM
  • Thanks Dennis. Will check how can I use this information. Meanwhile, any pointers on using the graph API to fetch information.
    Monday, September 11, 2017 10:23 AM
  • Hi,

    To call APIs on Microsoft Graph you will need to use the Active Directory Authentication Library (ADAL) for JavaScript library and authenticate using the OAuth flow. The following articles for your reference:

    Call the Microsoft Graph API using OAuth from your web part

    https://dev.office.com/sharepoint/docs/spfx/web-parts/guidance/call-microsoft-graph-from-your-web-part

    Code example: https://github.com/wobba/spfx4fun/tree/master/GraphCallTest

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, September 12, 2017 1:32 AM
  • I was able to resolve this issue. So basically the issue was with the reply url wherein the Azure AD was trying to send the token back to 

     

    https://tenant.sharepoint.com/sites/mysite/SiteAssets/ADALTest.aspx

     

    and my reply-url's did not have that entry. I had only entered either my tenant url or site collection url. Added the full url and now works smoothly.

    • Proposed as answer by Dennis Guo Friday, September 15, 2017 10:12 AM
    • Marked as answer by SharePointGuy Friday, September 15, 2017 11:34 AM
    Friday, September 15, 2017 8:21 AM
  • Hi,

    Glad to hear that you solve this issue, thanks for your sharing.

    You can mark reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, September 15, 2017 10:12 AM