Sharepoint REST API Authentication

Anonymous
2024-08-06T10:33:13.2233333+00:00

I need get attachments on sharepoint list, but i can't get it by using graph api
I tried use sharepoint api with url is https://site.sharepoint.com/_api/web/lists/GetByTitle('title'), but response always is "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))", i tried oauth2, oauth2/v2.0 and get through https://login.microsoftonline.com and oauth2 on https://accounts.accesscontrol.windows.net has same error.
How can i resovle this issue?

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 24,981 Reputation points Moderator
    2024-08-23T01:53:36.0033333+00:00

    Hi,

    To access SharePoint resources using REST, you need to construct a RESTful HTTP request by using the OData standard, which corresponds to the desired client object model API. The endpoint for getting attachments for a list is https://{site_url}/_api/web/lists/GetByTitle('list_title')/items(item_id)/AttachmentFiles. Make sure to replace site_url, list_title, and item_id with the appropriate values. To authenticate your app, you can use OAuth 2.0 for authorization/authentication. You can get an access token that authorizes your app with a particular set of permissions for a user. You provide an access token through an HTTP header: Authorization: bearer {token}. To obtain an access token and sign the user in, see OneDrive for Business authentication. If you are still getting an "Access is denied" error, make sure that the user account you are using to authenticate has the necessary permissions to access the SharePoint list and its attachments.


    If the answer is helpful, please click "Accept as 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 comments No comments

Your answer

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