Blog by VStudio365

How to Call SharePoint REST API from Postman using OAuth2 Authorization Flow

In this Article, we’ll walkthrough how to Call SharePoint REST API from Postman using OAuth2 Authorization Flow

Prerequisites:

Implementation Steps:

  1. Register an application in Azure AD and add SharePoint Permissions
  2. Build HTTP Request in Postman to Obtain OAuth2 access token
  3. Send HTTP Request to SharePoint with OAuth2 access Token from Postman

Step 1: Register an application in Azure AD and add SharePoint Permissions

  1. Go to Azure AD (Directory linked to your M365 tenant)
  2. Select App Registration > New Registration > Fill out the form

    screenshot

    Note: Redirect URL https://oauth.pstmn.io/v1/callback.

  3. Copy Client ID and Tenant ID for later use

    screenshot

  4. Generate Secret: Certificates & Secrets > New Client Secret > Fill Description > Add

    screenshot

  5. Copy Secret (It won’t be visible later. So, note down for later use)

    screenshot

  6. Select target API to add Permission: API Permissions > Add a Permission > SharePoint

    screenshot

  7. Add Permission: Application Permissions > Select Sites.Read.All (or as required) > Add Permissions

    screenshot

  8. Grant Consent: Click ‘Grant admin consent for <tenant ID>’ (Status should turn to green)

    screenshot

Step 2: Build HTTP Request in Postman to Obtain OAuth2 access token

  1. Go to Postman
  2. Create HTTP Request : Click New > HTTP Request

    screenshot

  3. Build HTTP Request : Fill Verb, Url and headers

    screenshot

    • HTTP Method : GET
    • HTTP Request : <site-url>/_api/web/lists
    • Headers :- Accept : application/json;odata=verbose
  4. Go to Authorization tab, select Oauth 2.0 in type field
  5. Navigate to Configure New Token and fill values as below and click on Get New Access Token

    screenshot

    • Token Name: <friendly name>
    • Grant Type: Authorization Code
    • Callback URL: https://oauth.pstmn.io/v1/callback
    • Auth URL: https://login.microsoftonline.com/common/oauth2/authorize?resource=https%3A%2F%2F<tenant_name>.sharepoint.com (refer tenant name from SharePoint Site URL)
    • Access Token URL: https://login.microsoftonline.com/common/oauth2/token
    • Client ID: <client ID> (copied from Step #1 point #3)
    • Client Secret: <secret> (copied from Step #1 point #5)
    • Scope: <Leave empty>
    • State : <Leave empty>

    Note: user will be prompted to fill username & password

  6. After Authentication, click proceed > Use Token

    screenshot

Step 3: Send HTTP Request to SharePoint with OAuth2 access Token from Postman

  1. Click Send

    screenshot

  2. Check response from SharePoint :) :)

    screenshot

Summary