Using document_url parameter and site_id can we identify whether a particular document is inside a Document library or not

GSH-1402 105 Reputation points
2025-02-14T05:09:40.69+00:00

In SharePoint we can create a Documents inside the site itself or we can create a new Document library inside the site and create the file inside that. When a document has been created inside a Document library we got a document_url like below,

ex: https://{tenant}.sharepoint.com/sites/{site name}/Test space/Document.docx

If I have the site_id and this document_url, can I check whether a document is inside a Document library or not.

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

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 50,006 Reputation points Microsoft Vendor
    2025-02-14T08:59:31.86+00:00

    Per my research, you don't need site id, only need the file URL to check whether a document is inside a document library through Graph.

    Here is an example:

    POST https://graph.microsoft.com/v1.0/search/query
    
    {
        "requests": [
            {
                "entityTypes": [
                    "driveItem"
                ],
                "query": {
                    "queryString": "path:\"https://tenant.sharepoint.com/sites/emilytest/doc1/Book1.xlsx\""
                }
            }
        ]
    }
    

    If the document is inside a document library, it will return "total": 1.

    enter image description here


    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.


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.