0

I'm working on a SPFX webpart with ReactJS that does some service calls to MS Graph API REST in order to show user data: user's display name, user's mails, user's calendar events and user's Teams. However, only user info service call ("/me" in Graph) retrieve data... Other calls show error: "ResourceNotFound - Resource could not be discovered" despite of same service call works properly if I make it with Graph Explorer.

In case of retrieving emails ("/me/messages"), I'm testing with a user who has Office365 Exchange mail account, but he hasn't admin role in SP Tenant. My webpart has "Mail.Read" and "Mail.ReadWrite" permissions (and other more, example "User.Read.All" in order to read user's Teams). I've test in SP Workbench and deploy my webpart in a page in SP tenant, approving all pending permissions in webApiPermissionManagement, but still doesn't work :(

Also, in Azure Portal my webpart shows that it has a delegated "Read user mail" permission. I don't know if I miss some configuration here, but I think that I aprroved every permission I could with another user who has admin role...

So, I have two users of differents organizations: one who has mail Exchange O365 with permissions in SP site but not admin role, and another who is the owner of SP Tenant but hasn't exchange mail (Im not testing webpart with this user).

In my code, the service call for retrieving mail list is:

  this.props.context.msGraphClientFactory.getClient().then(
    function(client: MSGraphClient) {
      client
      .api("me/messages")
      .version("v1.0")
      .select("receivedDateTime,from,subject")
      .filter("isDraft eq false")
      .orderby("receivedDateTime DESC")
      .get((error, response) => {
        if(error) {
          console.error(error.message);
          return;
        }
        MailHelper.GetMailsFromResponse(response); //Custom helper in order to format successful response
      });
    }
  );

(I saw how to call Graph client here: https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph#use-the-msgraphclient-in-your-solution)

As I said before, when I'm calling "/me/messages" service call, I'm gettinga 404 error: "ResourceNotFound - Resource could not be discovered", instead of emails list... but if use Graph Explorer, it works fine. I think that I've may skipped some permission configuration, but I don't know which one. I have tried with various Microsoft Tutorials about connect Graph and SPFX, but none works for me. Any idea? I'm kinda desperate.

Mfdezvil
  • 1
  • 2
  • What happens if you add a / before 'me' and remove the version line? (Looking at the Microsoft graph js sdk documentation https://github.com/microsoftgraph/msgraph-sdk-javascript ) – baywet Jan 30 '19 at 12:20
  • Same error :( MSGraphClient forms url as usual ("https://graph.microsoft.com/v1.0/me/messages?$select=receivedDateTime,from,subject&$filter=isDraft%20eq%20false&$orderby=receivedDateTime%20DESC") and returns same error of "Resource could not be discovered" – Mfdezvil Jan 30 '19 at 13:15
  • Could you look at the network tab and copy/paste the full URL of the request that's generated please? – baywet Feb 12 '20 at 17:33

0 Answers0