Using Nintex Workflow with SharePoint Rest Api

Senthil Kumaresan
 
SharePoint Consultant
September 24, 2015
 
Rate this article
 
Views
20681

Nintex workflows have powerful utilities that help to perform some of the tedious operations like batch updating content or configuration. One such action is the “Web Request”.

I had a scenario where I would need to disable content approval feature from some of the libraries in a set of sites that reside in site collections on different web applications. There are different approaches to do this. First is to write a PowerShell script. But writing a script is pretty easy but executing will take time as I had an environment where the SharePoint Farm is managed by a dedicated server team and I will have to wait to run the script on a change window. Second is to write a .Net Client Side Managed Code program to iterate across all the sites in site collection that reside in different web application which needs extensive coding to.

But there was even easier approach to use Nintex workflows for batch operations which I luckily had in my organization’s SharePoint On-Premises environment. With the introduction of Rest in SharePoint 2013, it is easier now to perform CRUD operations on SharePoint objects using the “Web Request” action in Nintex Workflows.

I had the list of SharePoint Site Url’s in a SharePoint List where I would need my workflow program to iterate through all the sites and remove content approval feature from a library on the site.

There are 2 categories of Http Methods to use in the web request action.

1. Get – Read operation to resources which the user defined in the web request action has rights to.

2. Post – Create, Update and Delete operations on resources which the user defined in the web request action has rights to.

a. For Update operation, A header X-HTTP-Method has to be set with value of MERGE

b. For Delete operation, A header X-HTTP-Method has to be set with value of DELETE

c. All Post operation requires a request digest token to validate post backs to SharePoint.

For my example, since I want to disable content approval for libraries in a set of sites, I would need to perform an update operation using the Post Http Method. I have designed the workflow so that it performs a “for each” loop action to iterate through list of sites and calls the rest service for each site and performs the update operation.

First, to perform a Post method you will need a request digest token.

To get a request digest token you will have a perform a post operation to the Rest Url https://<Site Url>/_api/ContextInfo and store the response in a variable

clip_image001

Use Query XML action to query the Digest token value from the Response xml and store it in a variable which is required for the Post operation.

clip_image003

After getting the digest token, I can now call the Post method to perform the update operation on the list properties to disable the content approval on the list using the web request action.

clip_image004

Note, I have modified the content type to “application/json;odata=verbose” since I am sending a Json request in the body of the web request.

Since this is an update operation, I have added 3 headers

1. X-HTTP_Method : MERGE

2. X-RequestDigest : <Digest token got earlier in a variable>

3. IF-MATCH : *

The IF-MATCH: * header is used to overwrite any changes that has already been changed on the server.

The body contains the Json input to perform the merge operation. For all SharePoint Rest API related info check msdn link

So it is pretty simple to perform any Batch CRUD operations using Nintex Workflows, Instead of writing a script.

Author Info

Senthil Kumaresan
 
SharePoint Consultant
 
Rate this article
 
SharePoint Architect – Consulting on SharePoint Infrastructure, IT Governance and Apps Development. ...read more
 

Leave a comment