Search code examples
python-3.xapigraphmicrosoft-graph-apisharepoint-online

Always getting empty response while using the graph search API for sharepoint document


I am using following graph search API to search sharepoint document using the document id.

GET /drives/{drive-id}/root/search(q='{search-text}')
GET /sites/{site-id}/drive/root/search(q='{search-text}')

My api url :

https://graph.microsoft.com/v1.0/sites/{site id}/drive/root/search(q='DlcDocId:doc id')

My response

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
    "value": []
}

I am getting empty response with response code is 200.

My access token have full access with following scope

"scp": "Files.Read.All Group.Read.All GroupMember.Read.All User.Read User.Read.All profile openid email"

I want item id with item details as api response. So that we can use item id for further action. Not able to fetch the item id from search query.

I am stuck here. Please help me out.

Thank you


Solution

  • Go to Portal.Azure.com > App Registrations > [Your App Registration Name].

    You will need to check your permissions there under API permissions. For accessing SharePoint items, via Microsoft Graph, we have the following settings:

    [API / Permissions name]

    Microsoft Graph

    • Sites.Manage.All
      (we have because we do a lot of doc management via code)
    • Sites.ReadWrite.All
    • User.Read

    You may just need the Sites.ReadWrite.All under Microsoft.Graph, but I wanted to provide context to do other things as well if coding against SharePoint Online.