Hi @James ,
I will recommend you to use App-Only to access SharePoint Online. Please refer to the following steps to grant access.
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
And here is the ajax call to get access token:
$.ajax({
type: 'POST',
crossDomain: true,
url: 'https://accounts.accesscontrol.windows.net/<tenantID>/tokens/OAuth/2',
headers: {
"content-type": "application/x-www-form-urlencoded"
},
data: {
"grant_type": "client_credentials",
"client_id": "<ClientID>@<TenantID>",
"client_secret": "<ClientSecret>",
"resource": "00000003-0000-0ff1-ce00-000000000000/<sitename>.sharepoint.com@<TenantID>"
},
success: function(data) {
//data.token_type returns "Bearer"
//data.access_token returns < AccessToken >
var at = data.token_type + " " + data.access_token;
//caal the REST API with the at variable in header
},
error: function(data, errorThrown, status) {
}
});
Here is the detailed steps for your reference:
https://global-sharepoint.com/sharepoint-online/in-4-steps-access-sharepoint-online-data-using-postman-tool/
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.
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.