SharePoint Developer Tools: How To Test & Debug SharePoint REST API Endpoints (POST Requests)

This is the second are article in the series of using Fiddler as Debugging & Testing Tool for SharePoint REST API EndPoints.

You can read the article on GET Request here:

SHAREPOINT DEVELOPER TOOLS: HOW TO TEST & DEBUG SHAREPOINT REST API ENDPOINTS (GET REQUESTS)

POST requests are different in nature than GET requests. They require more authentication layers to get through in order to push the data to SharePoint Lists and Libraries.

In order to run the POST request successfully we need an additional request header “X-RequestDigest” which is not but the User Authentication Token.

In order to request this token from SharePoint we need to make of “contextInfo” endpoint that will return the “FormDigestValue” containing the required user authentication token.

Now let see how we can request Authentication Token from SharePoint

Get Authorization Token

http://<Host Name>_api/contextinfo

1

2

Once we get the Authentication Token from SharePoint, we can add this token information in the Request Header of each of the POST requests

Request Headers

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
X-RequestDigest: 0xE1AE266A42214DA2940689826F68426D10620220CEDD3093CA2C234993E4ECA265BA57D357E8D3BD32F56660613CADBF72495F2C858B38F7C9B9C3CAD797F6D5,06 Feb 2017 01:22:08 -0000

Once we are ready with Request Headers we can start issuing POST Requests as shown below-

Add Data to List

Let’s consider we have a list called Categories as shown below-

3

First see the XML return based on querying schema for Categories List using following URL

http://<Host Name>/_api/Web/Lists/getByTitle('Categories')

4

Then we will see the XML return based on querying for Categories List Items using following URL

http://<Host Name>/_api/Web/Lists/getByTitle('Categories')/Items

5

Next step is to prepare the Request Body and we have to include following properties to add the items.

Please note that I am taking properties that are required for this list to add the category and add any desired number of properties to the Request Body as per the schema of the target list.

Request Body

"__metadata": { type: " SP.Data.CategoriesListItem" },
Title: "Category From Fiddler",
CategoryID: 9,
Description: “New Category Added from Fiddler”

6

Once we execute this request we can inspect the response to ensure that the request item has been added successfully to the Categories List.

7

Also we can validate this new item added by browsing Categories List

8

Update List Item

http://<Host Name>/_api/Web/Lists/getByTitle('Categories')/Items(9)

For update request you have to include “eTag” value that was returned with the item during the initial query to the Request Body. SharePoint uses this value to determine if there is any updates made to the item since it is last queried.

“If-Match: *” can be used to match any “eTag” value resulting in the operation being performed regardless of the actual value.

“X-Http-Method: PATCH” is to override the existing values

So the request body would be like this

IF-MATCH: *
X-Http-Method: PATCH
{
    "__metadata": {
    type: "SP.Data.CategoriesListItem"
},
Title: "Category From Fiddler - Updated",
Description: "New Category Added from Fiddler - Updated"
};

9

Once the request executed successfully we can see the item is updated in the Categories List

10

Delete List Item

http://<Host Name>/_api/Web/Lists/getByTitle('Categories')/Items(9)

Delete operation is more or less similar to Update operations.

11

In case of delete we will use of “X-Http-Method: DELETE” in the Request Body

Request Body

IF-MATCH: *
X-Http-Method: DELETE

12

Once the request executed successfully we can validate the item is deleted from the list.

13

Add New List

http://<Host Name>/_api/Web/Lists

Adding a new SharePoint List involve a little bit more of configuration information in Request body apart from request headers

Request Headers

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose

Request Body

Content-Length: 0
{
"__metadata": { type: "SP.List" },
"AllowContentTypes":true,
"ContentTypesEnabled":true,
"Description":"This is Task List Created using Fiddler",
"BaseTemplate": 107,
"Title": "Task List By Fiddler"
}

14

Once this request has been executed successfully we can see the Response Body holding information about newly added SharePoint List

15

Also we can see this new list added to SharePoint by browsing the respective site

16

17

Also we can verify the “AllowContentTypes” & “ContentTypesEnabled” properties are configured as expected by browsing the Advanced Properties of the new List as shown below-

18

Delete List

http://<Host Name>/_api/Web/Lists/getByTitle('Task%20List%20By%20Fiddler')

Deleting a list is rather simpler than adding it. It takes “X-Http-Method: DELETE” to be added to the request header and rest will be done for you.

 Request Headers

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
Content-Length: 0
IF-MATCH: *
X-Http-Method: DELETE

19

Once the request has been completed, it will delete the required list from SharePoint Lists Collection.

20

Hope you find it helpful.

Advertisements

SharePoint Developer Tools: How to Test & Debug SharePoint REST API Endpoints (GET Requests)

In this article we will understand how 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 increase with shift in modern SharePoint development paradigms that favors more if Client Side Development Techniques/Strategies/Platforms rather than traditional Farm Solutions.

In this upcoming section of this article I 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 to authenticate you against SharePoint based on the User Token stored once.

1

If this setting is not enabled you might encounter “401 UNAUTHORIZED” as shown below-

2

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

3

Once the request is issued using Fiddler “Composer“, we can see the request details in the left pane

4

When you click on 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.

5

Similarly we can execute other GET Requests as shown in upcoming Screen Shots-

Get List Object

http://<Host Name>/_api/Web/Lists

6

7

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))

8

9

Get Web filtered by Title

http://<Host Name>/_api/Web/?$select=Title

10

11

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

12

13

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

14

15

That is all for this demo.

Hope you find it helpful.

Developer’s Tools: How To Generate Basic Authentication Token

This demo is about another tool that I worked out during an assignment while working with an integration scenario using web services supporting Basic Authentication.

Problem with basic authentication is that you have to keep username and password stored somewhere in order to generate the authentication token.

Since I was integrating external web services with SharePoint so I felt to delegate the Token Generation Process to an external tool and consume the Authentication Token directly with out keep user name and password to be stored in the code itself.

To run this demo I have created a simple interface that takes username and password as input and generates the Basic Authentication Token and will display it in “Authentication Token” section

1

Now let’s discuss the code behind this functionality:

Step 1 is registering button click event by mapping a function “get Token”

Step 2 is calling “getBasicAuthenticationToken” function by passing user name and password

Step 3 is preparing format required to convert plain text into hash value in base-64 format

Step 4 is calling JavaScript function “btoa” which will encode the plain text into “base-64” format which is a required hash value to prepare Basic Authentication Token.

“Basic” is prefixed to the hash value to comply with Basic Authentication Token Standards

2

That is it for the code.

Now when we click “Get Authentication Token” button we will see the authentication token in the “Authentication Token” section.

3

This token can be used for any Web Service supporting basic authentication, and this strategy can be merged with other functionalities too in order to generate this token on the fly.
Hope you find it helpful.

SharePoint Developer Tools – Get Your Gears

There are quite a number of Must to Have developer tools that every SharePoint Developer must have in its arsenal in order to boost its own Productivity while developing solutions on SharePoint Platform.

Few of the tools which are my personal favorites also are listed below:

CAML Designer 2013

CAML Designer can generate the CAML Query Stubs based on the inputs provided by the developer and can quickly give a handle on even complex query formations.

It is not just about the Formation of Queries but also offers code Transition from actual CAML Query to

  • Corresponding Server Side Object Model Code
  • Corresponding Managed Client Side Object Model Code
  • Corresponding JSOM & REST API Calls
  • Corresponding PowerShell Code

1

Download Path: http://biwug-web.sharepoint.com/SitePages/Caml_designer.aspx

SharePoint Manager 2013

SharePoint Manager has got quite a simple and intuitive interface which allows you to quickly and easily navigate down the farm and investigate settings, properties, schema XML and so on. Most of the things in your SharePoint environment can be investigated from this tool.

This tool allows you to quickly navigate the Site Hierarchy and objects, and you can also get a quick handle on Schema of List, Fields and on object properties like Object GUIDs, Object Titles and so on.

2

Download Path: http://spm.codeplex.com

ULS Viewer

ULS Viewer allows you to look into the SharePoint ULS Logs in real time by parsing the Logs. The information (Correlation ID, Date Time Stamp, Event Source Process and so on )exposed by this tool is really useful for productive debugging capabilities.

3

With the evolution of SharePoint 2013 Developer Dashboard also includes these capabilities of reading & parsing ULS logs. Developer Dashboard contains a separate tab by the name “ULS” where we can see the ULS log entries.

4

Download Path: http://www.microsoft.com/en-in/download/details.aspx?id=44020

CKS Dev

CSK Dev is a Visual Studio extension which adds a bunch of new Project items for SharePoint Projects that are really helpful in increasing productivity of a developer.

Extension Project Items included

  • WCF Service SPI template
  • Contextual Web Part SPI template
  • Branding SPI Template
  • ASHX SPI template
  • Upgrade Solution Step
  • Restart IIS Step
  • Copy To SharePoint Root Step

And many more…

5

6

Download Path: http://visualstudiogallery.msdn.microsoft.com/cf1225b4-aa83-4282-b4c6-34feec8fc5ec

Color Palette Tool for Branding

Color Palette allows you create a composed looks for SharePoint 2013.

7

Download Path: http://www.microsoft.com/en-us/download/details.aspx?id=38182

SharePoint 2013 Search Tool

SharePoint Search Tool allows to you create and test SharePoint Search Keyword Query backed up by SharePoint REST API paradigm. It also allows you to analyze the Query Stats and adjust them as per the required output.

8

Download Path: http://sp2013searchtool.codeplex.com/

Fiddler

Fiddler is a Web Proxy that allows to Debug Web Traffic, do Performance Testing, HTTP/HTTPs Traffic Recording, Security Testing and so on.

The use of Fiddler becomes utmost necessary now with the evolution of SharePoint 2013 which is more focused on Development Strategies based on Client Side Scripting Technologies.

9

Download Path: http://fiddler2.com/get-fiddler

SPCAF – SharePoint Code Analysis Framework

SharePoint Code Analysis Framework helps to validate your custom SharePoint Solutions and Apps against Best Coding Practices prescribed the industry drawn by various industry standards.

This framework can be really helpful to let you verify if your custom solutions are Stable, Complying with Company Policies, Following Coding Best Practices, Well Designed and Maintainable and much more.

10

Download Path: http://www.spcaf.com

.NET Reflector from Red Gate

.Net Reflector is one of the best tools I have ever used for understanding code of Third Party DLLs for which I even did not had the Source Code.

Reflector allows you to look into the DLLs to see the code encapsulating inside it to understand its functioning.

11

Download Path: http://www.red-gate.com/products/dotnet-development/reflector/

PowerShell Tools for Visual Studio

This is an excellent Visual Studio Extensions for PowerShell which enables code intellisence for PowerShell Scripts within Visual Studio Editor.

12

Download Path: http://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597

SPFastDeploy

This tool is specially designed to enhance the productivity while working with SharePoint App.

This tool is best suited for pushing the code changes quickly to SharePoint Apps without re-deploying the Apps. This could save a significant amount of time during App Development.

13

Download Path: http://visualstudiogallery.msdn.microsoft.com/9e03d0f5-f931-4125-a5d1-7c1529554fbd

Advanced REST Client plugin for Google Chrome

This is a Chrome Plugin that allows you configure and investigate REST Queries by configuring and executing REST API Call through the tool UI. It also allows us to look for the Stats of the REST Queries in execution.

14

Download Path: https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US

Postman – REST Client plugin for Google Chrome

This is again a Chrome Plugin that allows you deal with REST Calls same as “Advanced REST Client plugin for Google Chrome”.

It is just a matter of choice which one you prefer to work with.

15

Download Path: https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm

SharePoint 2013 Client Browser

This is the similar tool as SharePoint Manager with the only difference that it allows us to connect to SharePoint Sites Remotely using Client APIs. So now no more need to login to SharePoint Server to browser SharePoint Site Objects using this tool.

16

Download Path: https://spcb.codeplex.com/

smtp4dev

This is an awesome tool for testing SharePoint Send Mail Functionalities no matter if it is Custom or OOB functionality that we are testing.

It is used to verify if the SharePoint is sending mails to the recipients properly. This tool intercepts the mails that were sending to the recipients by SharePoint and allows you to view them in its own UI.

17

Download Path: http://smtp4dev.codeplex.com/

PowerGUI

PowerGUI is one of the best tools available for PowerShell Programming. It provides intellisence support for writing PowerShell Scripts at the same time provides lot of useful windows for Debugging purposes.

18

Download Path: http://powergui.org/downloads.jspa

SharePoint Software Factory

The SharePoint Software Factory is a Visual Studio Extension helping SharePoint Beginners, as well as experienced developers to create, manage and deploy SharePoint solutions without having to know schema internals of the SharePoint Artifacts.

19

Following is the list of few of the features offered by this extension-

20

And many more…

For a detailed list of available features you can visit : http://www.matthiaseinig.de/docs/SPSF/OutputHTML/SPSF_RECIPES_INDEX.html

Download Path: https://spsf.codeplex.com/

SharePoint Solution Deployer

SharePoint Solution Deployer helps you to deploy SharePoint solution packages (.wsp) to multiple SharePoint environments. It deploys, retracts and upgrades one or more WSPs and can be extended to perform additional custom tasks in PowerShell before or afterwards.

It provides a simple XML configuration file which allows you to define the deployment environment by using variables i.e. to perform different actions on different URLs depending to which farm you are currently deploying.

21

Download Path: https://spsd.codeplex.com/

SharePoint Diagnostic Studio 2010

Microsoft SharePoint Diagnostic Studio 2010 (SPDiag version 3.0) was created to simplify and standardize troubleshooting of Microsoft SharePoint 2010 Products, and to provide a unified view of collected data.

This tool can be used for-

  • Gathering relevant information from a farm
  • Displaying the results in a meaningful way
  • Identifying performance issues
  • Sharing or exporting the collected data
  • Providing reports for analysis

And much more…

22

Download Path: https://technet.microsoft.com/en-us/library/hh144782(v=office.14).aspx

SPServices

SPServices is a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.

23

Download Path: http://spservices.codeplex.com/

SharePoint LogViewer

SharePoint Log Viewer is a Windows application for reading and filtering Microsoft SharePoint ULS Logs.

It offers the following key features-

  • View multiple SharePoint log files at once
  • Search by any field
  • Filter the log by any field
  • File drag & drop support
  • Live monitoring for entire farm
  • Export filtered log entries
  • Bookmark log entries
  • Get popup notification of SharePoint log events from system tray
  • Receive email notifications on errors
  • Redirect log entries to event log
  • Supports SharePoint 2007, 2010 and 2013

24

Download Path: http://sharepointlogviewer.codeplex.com/

FxCop

FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements. Many of the issues concern violations of the programming and design rules set forth in the Design Guidelines, which are the Microsoft guidelines for writing robust and easily maintainable code by using the .NET Framework.

25

Download Path: https://msdn.microsoft.com/en-us/library/bb429476(v=vs.80).aspx

JavaScript Beautifier

This online tool is used to beautify, unpack or De-obfuscate JavaScript and HTML, make JSON/JSONP readable, etc.

26

Download Path: http://jsbeautifier.org/

JSON Formatter & Validator

This is an online tool to that can be used to validate the JSON Packets

27

28

Download Path: https://jsonformatter.curiousconcept.com/

Being a SharePoint Developer I can say using these tools should be the second habit for SharePoint Developers to enhance their development capabilities which results in quick delivery turn around.

Hope you all find it helpful.

How to Get Public Key for SharePoint Projects

Visual Studio Version: 2010

SharePoint Foundation development projects often involve a mixture of imperative coding and XML markup. Frequently, you add your new assembly’s Public Key Token to a project file, such as an XML configuration file.

If your Visual Studio project is based on any of the SharePoint 2010 project templates in Visual Studio, you can simply insert the placeholder $SharePoint.Project.AssemblyPublicKeyToken$ where the Public Key Token should be in most kinds of project files (but not .cs or .vb files or other compilable files).

When you build and deploy the project, Visual Studio will replace the placeholder with the Public Key Token in the copies of the files that are actually deployed.

If you need to insert the Public Key Token in a file that does not support the placeholders, you will need a way to obtain the Public Key Token. This topic explains how to add an item to the Visual Studio Tools menu that can be used to obtain the Public Key Token of an assembly under development.

  • Launch Visual Studio and click on External Tools under Tools Menu as shown below:

1

  • Click on Add button

2

  • Enter Title of your choice
  • Enter Command as the path to sn.exe file, you can find this command line utility at the following location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\sn.exe
  • Enter Arguments as -T $(TargetPath), this will be replaced by the selected project later on

Make sure “Use Output Window” checkbox is checked so that you can be able to get the Public Key on the Output Window with in Visual Studio.

3

  • Select the project for which you want to find out the Public Key

4

  • Click on Get Public Key under Tools menu

5

  • Public Key Token is now available on the output window

6

That’s so simple yet powerful.

It is really useful for a SharePoint Developer to have these kind of tools handy.

Hope this will help someone in need…