Sunteți pe pagina 1din 16

WORKING WITH THE CALL HTTP WEB SERVICE

WORKFLOW ACTIVITY

Derek Nishino
Nishino Consulting
derek@nishinoconsulting.com

Agenda
What is the Call HTTP Web Service Workflow Activity?
What Can It Do?
SharePoint REST Web Services
SharePoint Designer Workflow Dictionary Variables
Retrieving Items from a SharePoint List
Writing to a SharePoint List
Gotchas

What Is It?
SharePoint Designer workflow activity for 2013-style workflows
Makes calls to REST web services, including the SharePoint web services
Allows looping through data such as items from a SharePoint list in a targeted way
NOT LIMITED TO CALLING SHAREPOINTS REST WEB SERVICES
HTTP GET, PUT, POST, DELETE
Must support OData and JSON

Dictionaries
A new type of workflow variable
Used to hold data structures for calling REST web services
Similar to concept of arrays in software development
Can also think of them as lists of data within your workflow
Can have Dictionaries nested in Dictionaries

Dictionary Actions
Build Dictionary
Get an Item from a Dictionary
Count Items in Dictionary

Connecting to SharePoint 2013 On-Prem


Create variables
restURL (string) contains URL to REST API call
Format is siteurl/_api/web/lists/getbytitle(list name)/items
Can test to make sure your URL is correctly formed by pasting into web browser

address bar, must be signed in to the tenant

requestHeaders (Dictionary) contains two headers that you add using the

Build Dictionary action


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

responseContent (Dictionary) holds the list content thats returned


reponseHeaders (Dictionary)

Connecting to SharePoint 2013 On-Prem


Add Call HTTP Web Service action
Should automatically create a String variable called responseCode

Set Call HTTP Web Service action properties as follows (easiest to set from

properties window)
Address = restURL variable
RequestType = HTTP GET
RequestHeaders = requestHeaders variable
ResponseContent = responseContent variable
ReponseHeaders = responseHeaders variable
ResponseStatuesCode = responseCode variable

DEMO

Connecting to SharePoint 2013 Online


Lots of confusing blogs and other articles out there that tell you to
Use Fiddler to find authentication token and other headers
Add unnecessary headers (x-request, content-length)
Hard code your authentication token into the web service call!

Actually much easier than that if youre just reading a list, just need

to add the Host name to the RequestHeader


Just the URL to your SharePoint Online tenant
e.g. nishinoconsulting.sharepoint.com

Looping Through Items


List items are returned to dictionary variable responseContent
List items are stored in dictionary item called d/results

Create a variable called Results, it will be used to get a count of the

number of list items returned


Use the Get an Item from a Dictionary action to get Results from
responseContent
item by name or path = d/results
dictionary = responseContent variable
item = Results variable

Looping Through Items


Need to tell the loop how many times to run and a way to keep track

of which item were working with


Create Integer variables to manage the loop
Count tells the loop how many times to run, populate it with the Count Items

in Dictionary action
Index keeps track of which item were currently working with in

resultsContent, set to have a default value of 0


IndexPlusOne used to increment the Index when we (cant just do an Index++

operation)

Looping Through Items


Create variables for each column from the results youre going to be working

with
Use Get an Item from a Dictionary to pull the column values from each row of

results into your variables


Use the variables the same way you would use any workflow variable
Use in workflow email
Write a message to the log
Perform comparisons
etc

Increment your Index by adding one to it


Need to use and intermediary variable (IndexPlusOne)

Filtering Results
Dont always want all items in a list
REST supports use of logical operators in the URL to filter results
Less Than, Equal To, Greater Than or Equal To, etc.

REST has operations for numbers, strings, and dates not all are supported by

SharePoint
Can specify columns, sort order, and more
Add ?$filter= without quotes to the end of your REST URL with the logical

operation after the =


e.g. ?$filter=ID gt 20 returns items in the list with an ID greater than 20

Use and to specify multiple filters


e.g. ?$filter=ID gt 20 and ID lt 50 returns list items with an ID greater than 20 but less

than 50

Gotchas
Can be difficult to troubleshoot
Authentication requirements in SharePoint Online make it

challenging to make REST calls outside of the immediate site


May not actually be possible to do cross-farm calls

Resources
Step-by-Step Guide for Reading List Items
http://

weblogs.asp.net/ricardoperes/looping-through-list-items-in-sharepoint-2013
OData Query Operations
https://msdn.microsoft.com/en-us/library/office/fp142385.aspx
MSDN Intro to SharePoint 2013 REST
https://msdn.microsoft.com/en-us/library/office/fp142380.aspx
Step-by-Step Guide for Updating List Items
http://blog.ctp.com/2014/03/12/updating-list-items-using-sharepoint-2013-work

flow-engine
/

THANK YOU!!!

S-ar putea să vă placă și