Get SharePoint list data using Postman

In this article, we will get SharePoint list items with a “Get” API call from Postman.

1. Register the SharePoint Add-in

  • Add your domain to the following URL and open it in your browser.

https://Domain.sharepoint.com/sites/SiteName/_layouts/15/appregnew.aspx

  • You will see the following screen.
  • Click on the “Generate” button for getting a unique “Client Id”.
  • Click on the “Generate” button for getting a unique “Client Secret”.
  • Add a title of your choice in the “Title” field.
  • Write “www.localhost.com” in the “App Domain” field.
  • Write “https://www.localhost.com” in the “Redirect URL” field.
  • Click on the “Create” button.

The app will be registered, and you will see the following screen.

Note: Make sure to save these details as they will be used in the next steps.

2. Grant permissions to the app

We need to grant permissions to the previously created app.

  • Add your domain and site name to the following URL and open it in your browser.

https://Domain.sharepoint.com/sites/SiteName/_layouts/15/appinv.aspx

  • You will see the following screen.
  • Paste the “Client Id” (from the previous step) into the “App Id” field and click on the “Lookup” button.

It will automatically populate the “Title”, “App Domain” and “Redirect URL” fields.

  • Copy the code given below and paste it into the “Permission Request XML” field and click on the “Create” button.

Code:

<AppPermissionRequests AllowAppOnlyPolicy=”true”>
<AppPermissionRequest Scope=”http://sharepoint/content/sitecollection/web/list” Right=”Read” /></AppPermissionRequests>

You can also set the “Scope” and “Right” according to your need from the list given below.

The Scope can have the following values (use as is, do not modify),

  • TENANT = http://sharepoint/content/tenant
  • SITE COLLECTION = http://sharepoint/content/sitecollection
  • SUB SITE = http://sharepoint/content/sitecollection/web
  • LIST/LIBRARY = http://sharepoint/content/sitecollection/web/list

The Right can have the following values (use as is, do not modify),

  • Read = only read access
  • Write = add/edit/delete
  • FullControl = full permissions
  • Click on the “Trust it” button.

3. Get the Tenant ID

Now we can access SharePoint Online to get Tenant ID, with Postman call using the app we have registered in the above steps.

  • Open the Postman client.
  • Select the “Get” method for the request.
  • In the “Request URL” field, copy and paste the following URL.

https://DomainName.sharepoint.com/_vti_bin/client.svc/

  • Go to the “Header” section, add “Authorization” as shown in the image below, and click on the “Send” button.

Header

KeyValue
AuthorizationBearer

This API call will fail with “401 Unauthorized error”.

No worries! We got what we needed from this step.

  • Go to the “Header” section and look for “Realm” and “Client id” as shown below.

Note: Make sure to save both the “Bearer realm” (Tenant ID) and “client id”.

4. Generate access token

Now we will generate an “Access token” to access our SharePoint list.

  • Open the Postman client.
  • Select the “Post” method for the request.
  • In the “Request URL” field, copy and paste the following URL.

https://accounts.accesscontrol.windows.net/[Tenant ID]/tokens/OAuth/2

Note: Tenant ID is the “Bearer realm” id that we got in the previous step.

  • Go to the “Header” section and apply configurations as shown in the image below.

Header

KeyValue
Content-Typeapplication/x-www-form-urlencoded
  • Go to the “Body” section and apply the following configurations.
KeyValue
grant_typeclient_credentials
client_idClientID (generated in app registration) @TenantID
client_secretClientSecret (generated in app registration)
resourceClientID(generated with bearer realm)/Domain.sharepoint.com@TenantID
  • Click on the “Send” button.

If it returns “Status 200”, it means that the connection to SharePoint was successfully created.

  • Go to the “Body” section and copy the “access token”.
  • Go to the “Authorization”, set the “Authorization type” to “Bearer token” and paste the “Access token” as shown below.

5. Get SharePoint list items

  • Select the “Get” method for the request.
  • In the “Request URL” field, copy and paste the following URL.

https://Domain.sharepoint.com/sites/SiteName/_api/web/lists/getbytitle(‘ListName‘)/items?$select=Title

  • Apply the following header configurations.

Header

KeyValue
Acceptapplication/json;odata=verbose
AuthorizationBearer [Paste value of  Bearer token]
  • Click on the “Send” button.

We have successfully retrieved the SharePoint list items.

If you face any error like “403 forbidden” or “401 Unauthorized”, check the configurations again.

Conclusion

We can get SharePoint list items using Postman “Get” call. To do so, we must register a SharePoint application and assign permissions to this application. Then we need to get the “Tenant ID” and “Access token”. After applying a few more configurations, we can access SharePoint list items.

That’s IT Folks