Search code examples
sharepointazure-active-directorymicrosoft-graph-apiazure-ad-graph-apisharepoint-rest-api

Getting list of all documents from share point


I am trying to implement functionality where I can get list of documents from share-point.I have tried this demo code from Azure directory implementation and login to account and also got details about sites and user data from graph API.

https://github.com/Azure-Samples/ms-identity-android-kotlin

I am able to get site data from graph API :

enter image description here

But when I am trying to get list then getting error or no value

enter image description here

I have also passed this authorization token to REST API but that too doesn't work.

enter image description here


Solution

  • You can try with scope Sites.ReadWrite.All instead of User.read, as I tested it using Graph Explorer and I got access denied as the scope permission was not consented. After I consent the permission, it worked .

    Example 1:

    Before Consent:

    enter image description here

    After Constent:

    I have created a test list on the Communication Site.

    enter image description here

    After that when I query for lists , I successfully get the above one I created.

    enter image description here

    Example 2 :

    I also tested it using a Application registered to Azure AD. It didn't return me any error or any value as well when I queried for lists using that app's credential's from Powershell.

    enter image description here

    After I add Sites.ReadWrite.All to the App's API permission's .

    enter image description here

    I can successfully get the Values of the lists.

    enter image description here

    To summarize it , it could be resolved in 2 ways :

    1. Changing the Scope shown on the screenshot given by you to Sites.ReadWrite.All instead of User.Read.
    2. Adding API permissions to the APP registration in the Azure AD for Microsoft Graph as shown in the example 2 second image.