In graph search api (/v1.0/search/query) for driveItem, how to query only OneDrive and only SharePoint results

Frank Hobert 1 Reputation point
2023-05-29T07:33:40.9166667+00:00

When using the graph search API for DriveItem entity

https://graph.microsoft.com/v1.0/search/query

with request body -

{
    "requests": [
        {
            "entityTypes": [
                "driveItem"
            ],
            "query": {
                "queryString": "contoso"
            }
        }
    ]
}

I am getting both OneDrive and SharePoint results, is there any filter/ field i can use to just get OneDrive or SharePoint results?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,342 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
957 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,236 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,486 Reputation points Microsoft Vendor
    2023-05-29T09:08:07.3433333+00:00

    Hi @Frank Hobert,

    As far as I know, there is no such filter in search currently. Since some drive items sync with SharePoint, you can query them both by drive id or item id. It's hard to differ if the item belong to onedrive or SharePoint. As a workaround, you can use following api to get drive items

    GET /drives/{drive-id}/items/{item-id}
    GET /drives/{drive-id}/root:/{item-path}
    GET /groups/{group-id}/drive/items/{item-id}
    GET /groups/{group-id}/drive/root:/{item-path}
    GET /me/drive/items/{item-id}
    GET /me/drive/root:/{item-path}
    GET /sites/{site-id}/drive/items/{item-id}
    GET /sites/{site-id}/drive/root:/{item-path}
    GET /sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem
    GET /users/{user-id}/drive/items/{item-id}
    GET /users/{user-id}/drive/root:/{item-path}
    

    And here is the api for SharePoint items

    GET /sites/{site-id}/lists/{list-id}/items/{item-id}
    

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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.