The Sharepoint file is accessible but when requesting document metadata, get's the 404 error

GSH-1402 65 Reputation points
2025-02-12T09:36:04.74+00:00

This is one of the problems faced by a Sharepoint user of my Add-in.

There is a shared Sharepoint document and he has access to it as well. Meaning he can view the file and edit as well. But through Add-in it returns File not found error.

I investigated the issue with him and the reason was, although he has access to the file, below GraphAPI call I use to get Document data returns 404 for his document.

GET https://graph.microsoft.com/v1.0/sites/{Site_id}/drive/root:{Document_path}

The site_id and document path is correct here and this happens only with that user and for other Sharepoint users this works fine.

Any idea, if there is a permission or something that should be enabled from his side.

Thank you very much.

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

Accepted answer
  1. Ling Zhou_MSFT 21,340 Reputation points Microsoft Vendor
    2025-02-13T09:09:41.1233333+00:00

    Hi @GSH-1402,

    Of course, please refer to the following steps:

    Drive id:

    Please use the following request to get the name and drive id of all the document libraries in the site and then filter by library name in your application. (Because the request does not support filter, so we can only query the drive id of all the document libraries.)

    GET https://graph.microsoft.com/v1.0/sites/{your site id}/drives?$select=id,name
    

    This is the returned response, the id property is the drive id: User's image

    Document_path:

    Use the following request to get information about the file. Note that the relative file path here starts with the folder containing the file and ends with the file name, or directly with the file name if there is no folder.

    GET https://graph.microsoft.com/v1.0/sites/{site id}/drives/{drive id}/root:/{relative file path}
    

    Not sure what Document_path is referring to, but there are webUrl and path properties in the response. If you need to know the details of the returned result, please refer to drive Item resource type.User's image

    If you have any questions, please do not hesitate to contact me.

    Moreover, if the issue can be fixed successfully, please click "Accept Answer" so that we can better archive the case and the other community members who are suffering the same issue can benefit from it.

    Your kind contribution is much appreciated.


2 additional answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 21,340 Reputation points Microsoft Vendor
    2025-02-13T02:35:45.08+00:00

    Hi @GSH-1402,

    Thanks for reaching out to us. We are very pleased to assist you.

    According to the information you provided and the research I have done, I may understand that you try to get the files in a site's default Shared Document library. If there is anything wrong, please correct me.

    If there is not anything wrong, then we need to check the following areas to troubleshoot the problem:

    1.Document Location & Site ID and Document Path:

    I know you've probably checked this many times, but I'd still recommend checking the site id and document path again (if the file is in a folder, then the path should include the folder). Confirm that the document is indeed located at the specified path. It might have been moved or deleted.

    2.Permissions:

    Verify that the user in question have the necessary permissions to access the document. Even if you have access to the file through other means, the API call requires specific permissions. According to this official documentation, user may need these permissions to use the request:

    User's image

    3.Permissions for documents in SharePoint:

    Please try removing the user's SharePoint access to the document and then re-granting it. Sometimes regranting the permissions will solve the problem.

    4.Gets all the documents in the Shared Document library.

    If the problem still exists, try using the following request to get all the files in the Shared Document library and see if the returned result contains the target document.

    https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root/children
    

    If you have any questions, please do not hesitate to contact me.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here. Your contribution will be highly appreciated.


  2. Ling Zhou_MSFT 21,340 Reputation points Microsoft Vendor
    2025-02-13T07:34:40.09+00:00

    Hi @GSH-1402,

    Thank you for your response.

    The problem is really strange. I don't think the problem is with the permissions, because insufficient permissions would return a 403 error (Access denied error), not a 404 error (Item not found error).

    First of all, please try to use another request to see if user still can't get the file.

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root:/{Document_path}
    
    Example:
    https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root:/Tech talk.pptx
    

    If the problem still exists, then please find out what is the difference between the account of the user with the problem and the accounts of other users, whether it is an external user or not, and whether there is any difference in the product certificates, etc.

    You can create a user with the same account and permissions to test. You can create an identical user account to test.

    If there is any question, please feel free to contact me.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here. Your contribution will be highly appreciated.


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.