Sharepoint API Authentication - Powershell

M Usman Siddiqui 0 Reputation points

Hello Everyone,

I want to use Sharepoint's Rest API to read and write to different documents but I dont know to get the auth token. Can any one explain the process to generate/create an auth token and how to use in a script to read an excel sheet?

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
7,116 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 20,061 Reputation points Microsoft Vendor

    Hi @M Usman Siddiqui,

    If you want to use Sharepoint's Rest API to read a file in sharepoint. You will need register a SharePoint app only first. Please refer to the following steps to register a sharepoint app first in the document

    Then you can use the client id and secret to connect sharepoint with pnp powershell and use Invoke-PnPSPRestMethod to call rest api

    #Site collection URL
    $SiteURL = ""
    #Connect to SharePoint Online with ClientId and ClientSecret
    Connect-PnPOnline -Url $SiteURL -ClientId "yourclientid" -ClientSecret "yoursecret"
    $output = Invoke-PnPSPRestMethod -Url '/_api/web/lists?$select=Id,Title'

    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.