WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting...

16
WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting [email protected]

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.

WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY

Derek Nishino

Nishino Consulting

[email protected]

Page 2: 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

Page 3: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.

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.

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.

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.

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.

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.

DEMO

Page 9: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.

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.

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.

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.

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.

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.

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 16: WORKING WITH THE “CALL HTTP WEB SERVICE” WORKFLOW ACTIVITY Derek Nishino Nishino Consulting derek@nishinoconsulting.com.

THANK YOU!!!