Consuming the SharePoint 2013 REST Service from SharePoint Designer

In SharePoint 2013 workflows  was introduced  a new action named Call HTTP Web Service. This action is flexible enough  to make requests to a variety web services including SharePoint REST service.

Figure 1 shows you the Call HTTP Web Service action on the SharePoint Designer 2013 surface.

Call HTTP Web Service Get Operation

 

Figure 1. SPD Workflow that demonstrates how to leverage Call HTTP Web Service action for Read operation

The specified example demonstrates how to perform Read operation for retrieving webs information:

  1. Create a workflow variable named Url and set it’s value to [%Workflow Context:Current Site URL%]_api/web/webinfos
  2. Insert Build Dictionary action to construct request headers. Add key value pairs  from table 1. Save results into a variable of type Dictionary and named  RequestHeaders
  3. Insert Call HTTP Web Service action. Open Properties window and specify it’s properties as shown in table 2.

 

Table 1. Request Headers for a RequestHeaders dictionary variable

Name Type Value
 Accept String  application/json;odata=verbose
 Content-Type String  application/json;odata=verbose

 

Table 2. Call HTTP Web Service action properties for Read operation

Property Name Value
 Address Set value to variable Url that was created in step 1
 RequestType Set value to HTTP GET
 RequestHeaders Set value to dictionary variable RequestHeaders that we’ve constructed to store request header properties in step 2 
 ResponseContent Create a new dictionary variable named Result for storing the response returned by the REST service and set value to variable Result

Scenario: Create Site Workflow

The below example demonstrates how to  perform Create operation using Call HTTP Web Service action, in particular how to create web site from a workflow. 

Note: In order to perform Create/Update/Delete operations using  Call HTTP Web Service action, App permissions for workflow have to be configured.  Please follow the steps in article Create a workflow with elevated permissions by using the SharePoint 2013 Workflow platform to configure App permissions for workflow.

   

Figure 2 shows you the configured Call HTTP Web Service action for creating web site

Call HTTP Web Service Create Operation

SPD Workflow

Figure 2. SharePoint Designer workflow for creating web site

Steps:

1.   Create a workflow variable named Url and set it’s value to [%Workflow Context:Current Site URL%]_api/web/webinfos/add

2,3 and 5.   Those steps serve for building payload to submit to the service.  RequestContent parameter of  Call HTTP Web Service action is used for setting payloads to submit to the service.  See tables 4,5 and 6 for a details.

4.   Insert Build Dictionary action to construct request headers. Add key value pairs  from table 1. Save results into a variable of type Dictionary and named  RequestHeaders

6.   Insert Call HTTP Web Service action. Open Properties window and specify it’s properties as shown in table 3.

Table 3. Call HTTP Web Service action properties for Create operation

Property Name Value
 Address Set value to variable Url that was created in step 1
 RequestType Set value to HTTP POST
 RequestHeaders Set value to dictionary variable RequestHeaders that we’ve constructed to store request header properties in step 4 
 RequestContent Set value to dictionary variable RequestContent that was created for storing payload in step 5
 ResponseContent Create a new dictionary variable named Result for storing the response returned by the REST service and set value to variable Result

 Specifying  web site  creation information

For building payload to be submitted to the service the following dictionary variables are initialized in the workflow

Table 4. Metadata dictionary variable

Name Type Value
 type String  SP.WebInfoCreationInformation
 

 

Table 5. WebParameters dictionary variable

Name Type Value
 __metadata Dictionary  Variable:Metadata
 Url  String  Parameter:WebTitle
 Title  String  Parameter:WebTitle
 Description  String  Parameter:WebDesc
 Language  Integer  Parameter:Language
 WebTemplate  String  sts
 UseIniquePermissions  Boolean  false

 

Table 6. RequestContent dictionary variable

Name Type Value
 parameters Dictionary  Variable:WebParameters

For passing information about web site, an Initiation form is used as shown on figure 3

CreateSiteInitForm

Figure 3. Initiation Form

 

 

References