Microsoft Graph Api => Search Sharepoint document library

David McDougald 40 Reputation points
2024-09-17T11:27:20.3833333+00:00

I have a sharepoint document library with nested folders. I would like to be able to query the library for all files that have a substring in the name underneath a particular folder.

According to this article, using V2 of the sharepoint online apis are equivalent to using the graph API for the following routes:

https://learn.microsoft.com/en-us/sharepoint/dev/apis/sharepoint-rest-graph

Graph URL SharePoint URL
https://graph.microsoft.com/v1.0/sites https://{tenant-name}.sharepoint.com/_api/v2.0/sites
https://graph.microsoft.com/v1.0/sites https://{tenant-name}.sharepoint.com/_api/v2.0/sites
https://graph.microsoft.com/v1.0/drives https://{tenant-name}.sharepoint.com/_api/v2.0/drives
https://graph.microsoft.com/v1.0/drive https://{tenant-name}.sharepoint.com/_api/v2.0/drive
https://graph.microsoft.com/v1.0/lists https://{tenant-name}.sharepoint.com/_api/v2.0/lists

According to the graph drive search documentation (https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http), the url formula for searching a drive looks like this:

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

so it seems to me that I should be able to search a sharepoint drive with the following url:

https://{tenant-name}.sharepoint.com/_api/v2.0/drives/{drive-id}/root/search(q='{search-text})'

but I recieve a 500 internal server error with the errors: { "error": { "code": "generalException", "message": "General exception while processing" }

I don't believe the URL is malformed since this formula: https://{tenant-name}.sharepoint.com/_api/v2.0/drives/{drive-id}/root returns data about the document library.

Do I have the wrong URL, or am I taking the wrong approach? I would love to know if there is another way to do this or if I am misreading your documentation.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,886 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,949 questions
{count} votes

Accepted answer
  1. Yanli Jiang - MSFT 25,621 Reputation points Microsoft Vendor
    2024-09-18T09:37:58.7+00:00

    Hi @David McDougald ,

    This is a very common error message, and no useful information can be obtained from it. It is recommended that you try using the Graph API in Graph explorer:

    https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='{search-text})'
    

    Fo your references:

    https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http

    https://learn.microsoft.com/en-us/graph/search-concept-files#example-1-search-files

    Good day!


    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.