Graph API Search for DriveItems within a drive does not return image files if I specify itemId

Rei 31 Reputation points

I'm using graph (Graph Explorer as well as my custom Azure Application which utilizes Graph API with the appropriate grants of Files.ReadWrite.All, Sites.ReadWrite.All) to search for specific files within a folder in a drive as documented here:

If I specify as follows it works:

However, if I specify the parent folder's Id, it returns empty or misses files (it seems it misses mostly png, jpg, adobe files):

    "@odata.context": "$metadata#Collection(driveItem)",  
    "value": []  

This is also true when I use the endpoint.
If I specify a path, it will not return results.

            "query": {  
                "queryString": "myfile path:\" Documents/PATH\""  

But if specify no path, or the Document library level, it will return the image files.

            "query": {  
                "queryString": "myfile path:\" Documents\""  

Funny thing is that it usually does actually successfully bring up text or PDF documents, but images like PNG and JPG often get lost. That is confusing to me as well. However if I do the drive root search, those images can be found. Is there a reason why when I specify the parent folder the graph api doesn't work properly? I've given it some time to index, but doesn't seem to change. Any help would be appreciated.

I also noticed that the webUrl on an image file is something like: Documents/Forms/DispForm.aspx?ID=2702

but a docx file is Documents/My Path/myfile.docx

I would appreciate any help on this.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,109 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,395 questions
0 comments No comments
{count} vote

Accepted answer
  1. Srinivasa Rao Darna 6,506 Reputation points

    Hi @Rei ,

    From Search for DriveItems within a drive, I don't see any reference example for /drives/{drive-id}/items/{folder-id}/search(q='{search-text}') for test this scenario.

    Using Search API, including ParentLink:/FolderName, along with Path should be able to retrieve files and images as well from a parent folder within a document library.

    "requests": [  
            "entityTypes": [  
            "query": {  
                "queryString": "searchstring AND Path: Documents AND ParentLink:/FolderName"  

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful