1. https://[tenant].sharepoint.com/sites/[SITE]/_layouts/15/appregnew.aspx
2. Look for message: The app identifier has been successfully created.
3. Go to: https://[tenant].sharepoint.com/sites/[SITE]/_layouts/15/AppInv.aspx
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web"
Right="Read" />
</AppPermissionRequests>
Available Rights:
Click [Create]
4. You will get a message: Do you trust TestingApp?
Click [Trust It]
5. Confirm access was added in the Site Collection App Permissions
https://[tenant].sharepoint.com/sites/[SITE]/_layouts/15/appprincipals.aspx
6. Open power shell and install the latest PnP.PowerShell (as of Nov. 2022)
Install-Module -Name PnP.PowerShell
7. Login to your sharepoint site to get the bearer token
Connect-PnPOnline -Url "https://[Tenant].sharepoint.com/[site]" -Interactive
Copy the bearer token to your clipboard
Get-PnPAppAuthAccessToken | Clip
If you want to see the token, you can also send this command:
Get-PnPAppAuthAccessToken
8. Open postman and create a new connection with the following settings:
Name: [Whatever you want]
Authorization > Bearer Token
Add to Body: Accept: application/json
30-p5021-sharepoint-api-postmant-bearer-token.png
9. Hit the Get button
10. Here is an example code you can use in a React component for example:
import React from 'react';
const App = () => {
const token = "yourtokenhere";
const [result, setResult] = React.useState();
React.useEffect(()=>{
fetch('https://example.test/', {
method: "POST",
headers: {"Authorization": `Bearer ${token}`}
}).then(res => res.json()).then(json => setResult(json));
},[]);
return (
<>
{JSON.stringify(result)}
</>
);
};
* Script Source: https://stackoverflow.com/a/65118513
Good Resources:
https://global-sharepoint.com/sharepoint-2/in-4-steps-access-sharepoint-online-data-using-postman-tool/