Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint Rest API how to get Access Token?

Just starting to work with SharePoint and Microsoft authentication and trying to get a SharePoint List into a JavaScript App. From Microsoft documentation, I need to use the following:

GET https://{site_url}/_api/web/lists/GetByTitle('List Title')
Authorization: "Bearer " + accessToken
Accept: "application/json;odata=verbose"

Have searched everywhere to find an definitive answer to how to obtain this accessToken. All the documentation I can find from Microsoft seem to be out of date. Does anyone know the current method to obtain an accessToken?

like image 678
L H Avatar asked Aug 09 '20 00:08

L H


People also ask

How do I get authentication token for REST API?

You use the POST operation on the api/get_token element to request your unique token that is required to authenticate the REST API requests. , and click Profile. Then, click Show token.


1 Answers

You could refer to this article to get access token:

https://global-sharepoint.com/sharepoint-online/in-4-steps-access-sharepoint-online-data-using-postman-tool/

Post https://accounts.accesscontrol.windows.net/<Tenant ID>/tokens/OAuth/2

Body:

grant_type     client_credentials
client_id      <Client ID>
client_secret  <Client Secret>
resource       00000003-0000-0ff1-ce00-000000000000/<tenant>.sharepoint.com@<Tenant ID>

My test result:

enter image description here

like image 192
Michael Han Avatar answered Sep 30 '22 18:09

Michael Han