i use sharepoint as cloud storage. I have a few .pdf files there now, and gave them public accessibility. So i'm available to open file by this url in anonymous window.
I need to use current files in another system (Salesforce), and i need to make api callouts to GET those files(base64).
I got access_token by this endpoint: https://accounts.accesscontrol.windows.net
When i tried to send GET request to this endpoint and set received Access_token as bearer token, i received 401 (Unauthorized).
I am available to get file if i get cookie from developer tools, and set as header. But for every file cookies are different and it work's for me only for testing.
Could you please explain me what i do wrong? And how to access public files via request (JavaScript). Thank you!
According to my research and testing, when you generate the access_token
, are permissions granted to the add-in, and what permissions are granted?
Please try granting Full Control
permission, for example: enter the below XML in the “Permission Request XML” box:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
</AppPermissionRequests>
If you want to get files in SharePoint, you can use the following Rest API:
GET https://{site_url}/_api/web/lists/GetByTitle('Test')/items
Authorization: "Bearer " + accessToken
Accept: "application/json;odata=verbose"
If you want to get a specific file, you can use the following REST API:
GET https://{site_url}/_api/web/lists/GetByTitle('Test')/items({item_id})
Authorization: "Bearer " + accessToken
Accept: "application/json;odata=verbose"
More information for reference:
Rest API: Working with lists and list items with REST
Generate access-token and access SharePoint: In 4 steps access SharePoint online data using postman tool
Similar issue for reference: How to use access token during making GET Request to Sharepoint file?
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.