Get drive item gives 404 not found even when search drive item gives the result

harryK9 11 Reputation points
2023-01-02T10:14:46.657+00:00

Hi,
I am using two apis, the search api to search for an item and get api to retrieve that item
Search API :

curl --location --request POST 'https://graph.microsoft.com/v1.0/search/query' \  
--header 'Authorization: Bearer ' \  
--header 'Content-Type: application/json' \  
--data-raw '{  
    "requests": [  
        {  
            "entityTypes": [  
                "driveItem"  
            ],  
            "query": {  
                "queryString": "dummy AND ContentType:Document"  
            }  
        }  
    ]  
}'  

Response :

{  
    "value": [  
        {  
            "searchTerms": [  
                "dummy"  
            ],  
            "hitsContainers": [  
                {  
                    "hits": [  
                        {  
                            "hitId": "01HAMQQBUWJF3IOKRBYQ7ORSQ",  
                            "rank": 1,  
                            "summary": "<c0>Dummy</c0><ddd/>",  
                            "resource": {  
                                "@odata.type": "#microsoft.graph.driveItem",  
                                "size": 79430,  

  
                                "id": "01HAMQQBUWJF3IOKRBYQ7ORSQ",  
                                "createdBy": {  
                                    "user": {  
                                        "displayName": "aaa",  
                                        "email": "aaa"  
                                    }  
                                },  
                                "name": "Dummy.pdf",  
                                "parentReference": {  
                                    "driveId": "b!2Cpw3HmhMk2Jb4dABGdSh920Acn19YVJgsiBLTU0zzz",  
                                    "id": "01HAMQOAQOD66PGXDSYRDY",  
                                    "siteId": "zzzz.sharepoint.com,dc702ad8-12e2-4d32-896f-12r12r,c901b4dd-f5f5-4985-asfa-812d35340767"  
                                },  
                                "webUrl": "www.dummy.com"  
                            }  
                        }  
                    ],  
                    "total": 453,  
                    "moreResultsAvailable": true  
                }  
            ]  
        }  
    ],  
    "@odata.context": "microsoft.com"  
}  

Here we have siteId - zzzz.sharepoint.com,dc702ad8-12e2-4d32-896f-12r12r,c901b4dd-f5f5-4985-asfa-812d35340767
and ItemId - 01HAMQQBUWJF3IOKRBYQ7ORSQ
Now if I call the get(preview) item api

curl --location --request POST 'https://graph.microsoft.com/v1.0/sites/zzzz.sharepoint.com,dc702ad8-12e2-4d32-896f-12r12r,c901b4dd-f5f5-4985-asfa-812d35340767/drive/items/01HAMQQBUWJF3IOKRBYQ7ORSQ/preview' \  
--header 'Authorization: Bearer {<!-- -->{accessToken}}'  

The result is returned 404.  

But the file is present on the system.
Access Token being used is Delegated Token

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,727 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,688 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,696 Reputation points Microsoft Vendor
    2023-01-02T14:45:37+00:00

    Hello @harryK9 ,

    Based on my test, I am able to get driveitem-preview, in the same way mentioned in the question by using search-concept-files to get the driveItem.

    Below is my test result,
    275439-search-id.png

    275457-preview-item.png

    Is the file present in default library?

    • Are you able to get the file with GET sites/{site-id}/drive/items/{item-id}
    • If the file is present in library other than, can you check if GET sites/{site-id}/drives/{drive-id}/items/{item-id} and POST sites/{site-id}/drives/{drive-id}/items/{item-id}/preview see what is the response

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