Unauthorized error when getting sharepoint list attachment despite having "Files.ReadWrite.All" permission

Josh Earel 0 Reputation points
2025-01-07T16:33:41.1933333+00:00

I am writing an ASP web application that can interact with a Sharepoint list, creating new items and updating existing items. We have an Attachments field in that list. Because accessing sharepoint list item attachment files is not available in the Graph API I am having to use the Sharepoint v1 REST API for that part of a web app. In Entra Id I have granted the application the "Files.ReadWrite.All" permission. When I call this endpoint to get the item details I get a link to the file:

https://{sharepointURL}/sites/{SiteName}/_api/web/lists/GetByTitle('{listName}')/Items('2323')?$expand=AttachmentFiles

It does give me information about the attached file, including the following URL:

https://{sharepointURL}/sites/{SiteName}/Lists/{ListName}/Attachments/2323/{fileName}.pdf

However, when I try and use that URL I get back 401 Unauthorized, but no further details. I can only assume I am missing some permission, as I am using the same authentication token I used for the original request. What am I missing here?

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

2 answers

Sort by: Most helpful
  1. Xyza Xue_MSFT 27,661 Reputation points Microsoft Vendor
    2025-01-08T02:42:27.2533333+00:00

    Hi @Josh Earel ,

    The 401 Unauthorized error message in SharePoint typically indicates that you do not have the necessary permissions to access the list attachment.

    1.To access sharepoint via a web url, first make sure you have access rights (e.g. read, edit, full control, not the “Files.ReadWrite.All” permission in the API) to the list item (attachment).

    User's image

    https://support.microsoft.com/en-us/office/customize-permissions-for-a-sharepoint-list-or-library-02d770f3-59eb-4910-a608-5f84cc297782

    2.Try adding the suffix “?web=1” to the url.

    https://{sharepointURL}/sites/{SiteName}/Lists/{ListName}/Attachments/2323/{fileName}.pdf?web=1
    

    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.


  2. Josh Earel 0 Reputation points
    2025-01-09T14:59:23.2166667+00:00

    I realized I was overthinking this as I had been doing so much work to get the API endpoint stuff working that I had just overlooked that this wasn't an API endpoint, it was providing a direct link to the actual file on sharepoint.


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.