1

Is there any api available in REST or JSOM to bring the shared documents to me in SharePoint using SPFx framework. I came to know that we can get details with Graph API. But I am more interested in simple REST queries instead of passing OAuth process in Graph API. Am I in right way?

1 Answer 1

0

SPFx provides an inbuilt graphHttpclient to make Graph API calls.

It has enough permissions (Group.ReadWrite.All, Reports.Read.All) to fetch the files shared with you with making any extra auth call. This will fetch all the files shared with you from both Onedrive and SharePoint.

You can use the below code:

private _getFilesSharedWithMe(): Promise<any> {

    return this.context.graphHttpClient.get(`v1.0/me/drive/sharedWithMe`, GraphHttpClient.configurations.v1).then((response: HttpClientResponse) => {
      if (response.ok) {
        return response.json();
      } else {
        console.warn(response.statusText);
      }
    }).then((respJSON: any) => {
      console.log(respJSON);      
      return respJSON;
    });

 }

Usage

var filesSharedWithMe = this._getFilesSharedWithMe();
filesSharedWithMe.then(function(result){
    console.log(result);
});

You need to add the below import statement:

import {GraphHttpClient,HttpClientResponse} from '@microsoft/sp-http';

However, do note that graphHttpClient is currently is in preview and will be deprecated in the future SPFx release. You can use AadHttpClient or MSGraphClient in the future which will be the replacement for graphHttpClient.

Reference - Call microsoft graph using graphhttpclient

1
  • Hey @Mihir, did you try the above code ? is it working for you ? If yes, could you please mark it as answer, thanks, cheers ! Feb 26, 2018 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.