SharePoint Developer Tools: How To Test & Debug SharePoint Rest API Endpoints (Get Requests)
In this article, we will understand how to utilize a famous developer productivity tool called Fiddler as REST API Test Client for SharePoint (though the target system could be anything with a valid REST API Endpoint).
Fiddler is primarily used as a Web Proxy that can allow you intercept REST API Request – Response Cycle. The usage of this tool has increased with a shift in modern SharePoint development paradigms that favors more client-side development Techniques/Strategies/Platforms rather than traditional Farm Solutions.
In this upcoming section of this article, .we will guide on how to use Fiddler to test REST API Call against SharePoint Data.
In this article, we will explore only GET type of Requests only.
To start with this demo launch Fiddler and go to “Rules” Menu and Select “Automatically Authenticate”, this will let Fiddler authenticate you against SharePoint based on the User Token stored once.
https://howtodowithsharepoint.files.wordpress.com/2017/08/112.png?w=800
If this setting is not enabled you might encounter “401 UNAUTHORIZED” as shown below
https://howtodowithsharepoint.files.wordpress.com/2017/08/22.png?w=800
Also, notice the request headers that are required to execute the SharePoint REST API Endpoint
GET Requests
http://<Host Name>/_api/<SharePoint Endpoint>
Request Headers
Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
Get Web Object
http://<Host Name>/_api/web
- Click on “Compose” Tab
- Select request type as “GET” from dropdown
- Specify the Request URL as http://<Host Name>/_api/web
- Click on “Execute” Button
https://howtodowithsharepoint.files.wordpress.com/2017/08/32.png?w=800
Once the request is issued using Fiddler “Composer“, we can see the request details in the left pane
https://howtodowithsharepoint.files.wordpress.com/2017/08/42.png?w=800
When you click the request in the left pane we can see the details breakdown in the right pane
For instance, we can click on “Inspectors” tab and then click on “JSON” tab.
JSON tab will display the response received from SharePoint in JSON Format.
https://howtodowithsharepoint.files.wordpress.com/2017/08/52.png?w=800
Similarly, we can execute other GET Requests as shown in upcoming screen shots
Get List Object
http://<Host Name>/_api/Web/Lists
https://howtodowithsharepoint.files.wordpress.com/2017/08/62.png?w=800
https://howtodowithsharepoint.files.wordpress.com/2017/08/72.png?w=800
Get Lists which are not hidden and have Items
http://<Host Name>/_api/Web/Lists?$select=Title,Hidden,ItemCount&orderby=ItemCount&$filter=((Hidden eq false) and (ItemCount gt 0))
Encoded Version of Request URL
http://<Host Name>/_api/Web/Lists?$select=Title,Hidden,ItemCount&orderby=ItemCount&$filter=((Hidden%20eq%20false)%20and%20(ItemCount%20gt%200))
https://howtodowithsharepoint.files.wordpress.com/2017/08/82.png?w=800
https://howtodowithsharepoint.files.wordpress.com/2017/08/92.png?w=800
Get Web filtered by Title
http://<Host Name>/_api/Web/?$select=Title
https://howtodowithsharepoint.files.wordpress.com/2017/08/102.png?w=800
https://howtodowithsharepoint.files.wordpress.com/2017/08/113.png?w=800
Get Web and Lists using Look Properties Expanding Lists Collection
http://<Host Name>/_api/Web/?$select=Title,Lists/Title,Lists/Hidden,Lists/ItemCount&$expand=Lists
https://howtodowithsharepoint.files.wordpress.com/2017/08/122.png?w=800
https://howtodowithsharepoint.files.wordpress.com/2017/08/132.png?w=800
Get Web and Lists using Look Properties Expanding Users Collection
http://sp-2016-ddev/_api/Web/?$select=Title,CurrentUser/Id,CurrentUser/Title&$expand=CurrentUser/Id
https://howtodowithsharepoint.files.wordpress.com/2017/08/142.png?w=800
https://howtodowithsharepoint.files.wordpress.com/2017/08/152.png?w=800
That is all for this demo.
Hope you find it helpful.