WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting...
-
Upload
millicent-hicks -
Category
Documents
-
view
214 -
download
2
Transcript of WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting...
![Page 1: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/1.jpg)
WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY
Derek Nishino
Nishino Consulting
![Page 2: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/2.jpg)
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
![Page 3: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/3.jpg)
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 SHAREPOINT’S REST WEB SERVICES
HTTP GET, PUT, POST, DELETE
Must support OData and JSON
![Page 4: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/4.jpg)
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
![Page 5: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/5.jpg)
Dictionary Actions
Build Dictionary
Get an Item from a Dictionary
Count Items in Dictionary
![Page 6: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/6.jpg)
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 that’s returned
reponseHeaders (Dictionary)
![Page 7: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/7.jpg)
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
![Page 8: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/8.jpg)
DEMO
![Page 9: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/9.jpg)
Connecting to SharePoint 2013 Online
Lot’s 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 you’re 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
![Page 10: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/10.jpg)
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
![Page 11: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/11.jpg)
Looping Through Items
Need to tell the loop how many times to run and a way to keep track of which item we’re 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 we’re currently working with in resultsContent, set to have a default value of 0
IndexPlusOne – used to increment the Index when we (can’t just do an Index++ operation)
![Page 12: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/12.jpg)
Looping Through Items
Create variables for each “column” from the results you’re 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)
![Page 13: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/13.jpg)
Filtering Results
Don’t 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
![Page 14: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/14.jpg)
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
![Page 15: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/15.jpg)
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-workflow-engine/
![Page 16: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.](https://reader035.fdocuments.in/reader035/viewer/2022081822/5697bfcf1a28abf838ca9e2a/html5/thumbnails/16.jpg)
THANK YOU!!!