SharePoint Online Rest API requests using the Network Console tool

Network Console tool is available for Chromium-based DevTools for making synthetic network requests over HTTP. It can be used during the dev-test loop for web APIs.
In part of this blog, we will see how we can use the Network Console tool to make SharePoint Rest API HTTP GET and POST requests.

Why Network Console tool?

Info

You do not need to provide any auth implementation. All tokens/cookies are already added to the API call, so all you need to do is start testing and changing your parameters.

Access Network Console Tool

  1. Download and Install Microsoft Edge based on Chromium Download

  2. To open DevTools, right-click the webpage and then select Inspect. Or, press Ctrl+Shift+I. DevTools opens.

  3. In DevTools, select the Network Console tab on the main toolbar or the Drawer toolbar at the bottom. If that tab isn’t visible, click the More tabs (More tabs icon.) Button or the More Tools (More Tools icon.) button.

The Network Console tool opens:
Access Network Console tool

Create HTTP GET Request to retrieve user profile properties

Tip

The Network Console tool is compatible with the Postman v2.1 and OpenAPI v2 schemas. You can import and export your existing Postman collections

  • Click on create a requests
  • Name the request. Get User Profile Properties
  • Select HTTP GET action from the dropdown
  • Enter the request URL. {SiteUrl}/_api/SP.UserProfiles.PeopleManager/GetMyProperties
  • Replace {SiteUrl} token with the current site path. This can also be initialized as an environment variable
  • Click on Send Button

Get User Profile Properties

Get digest token for non-GET HTTP requests

Note

When executing non-GET REST requests to the SharePoint REST API, you must include a valid request digest to your request. The digest proves the validity of your request to SharePoint.

Let’s create a GET HTTP request to get a valid form digest token. By default, a request digest token is valid for 30 minutes, so before using it, you must ensure that it’s still valid.

  • Click on create a requests
  • Name the request. Get Form Digest Token
  • Select HTTP GET action from the dropdown
  • Enter the request URL. {SiteUrl}/_api/contextinfo
  • Replace {SiteUrl} token with the current site path. This can also be initialized as an environment variable
  • Click on Send Button
  • Copy and save the FormDigestValue property value in Notepad.

Get Form Digest Token

Create HTTP POST Request to update user profile property

  • Click on create a requests
  • Name the request. Update User Profile Property
  • Select HTTP POST action from the dropdown
  • Enter the request URL. {SiteUrl}/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty
  • Replace {SiteUrl} token with the current site path. This can also be initialized as an environment variable
  • Add the following headers. Replace the x-requestdigest value with valid digest token copied in the previous step.
    HTTP Post Request Headers
  • Under Body section, Select Raw text
  • Select application/json option in the dropdown
  • Add the following JSON in the body
    {
    "accountName": "i:0#.f|membership|john@contoso.onmicrosoft.com",
    "propertyName": "AboutMe",
    "propertyValue": "Developer"
    }
  • Click on Send Button

Update User Profile Property

This tool is handy, especially when testing API requests against SharePoint Online. You dont need to handle authentication-related steps, For example, generating access tokens etc.

Author: Ejaz Hussain
Link: https://office365clinic.com/2022/07/26/making-spo-webapi-requests-networkconsole/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.