Getting started with SharePoint REST API in custom SharePoint workflows Reston SharePoint User Group
1. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
1
SM
Prashant G Bhoyar
Reston SharePoint User Group https://www.meetup.com/Reston-SharePoint-User-Group/events/244749034/
06 November 2017
Getting Started with SharePoint REST API in
Custom SharePoint Workflows
2. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
2
SM
Who AM I ?
• Born and raised in India
• Came to United States of America in 2007 for studies
• University of Maryland College Park Alumni
• Co-Author of the book “PowerShell for Office 365”
• Technical Reviewer of the book “Pro : SharePoint 2013 Administration”
• Organizer of SharePoint Saturday Baltimore (SPSBMORE)
http://www.spsevents.org/city/baltimore/baltimoretecc
• Organizer of SharePoint Saturday DC ( SPSDC )
http://www.spsevents.org/city/DC/summer2017
• Founder and Organizer of DC-Metro Office 365 User Group
Monthly in person & online event
http://www.meetup.com/DC-Metro-Office-365-User-Group/
• Recipient of Antarctic Service Medal
• Microsoft MVP ( Most Valuable Professional)
• Senior Consultant at Withum Smith and Brown PC
http://www.portalsolutions.net/
Former Portal Solutions
Focus on Microsoft Solutions and Services
Prashant G Bhoyar
(PGB)
3. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
3
SM
Withum Microsoft Solutions and Services
3
• Modern workplace
• Office 365 Implementations/
Migrations
• Turnkey Intranet Solution
• Managed Services
• Data Analytics
• Enterprise Mobility + Security
• Business Process Automation
• Dynamics 365
• Azure
4. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
4
SM
• 200 Level Session
• Approach
• Architecture of Workflow Manager
• Introduction to SharePoint REST APIs
• How to use SharePoint REST API in SharePoint Custom
Workflows?
• Demo
• Tips & Best Practices
• Key Takeaways
• Q&A
Agenda
5. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
5
SM
Slides: https://www.slideshare.net/pgbhoyar
Slides
7. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
7
SM
Audience Poll
How many of you are IT pros?
How many of you are Business Users?
How many of you are Developers?
How many of you are Power Users?
How many of you are already using REST APIs in Workflows?
7
8. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
8
SM
Approach
SharePoint REST APIs is itself a big topic
Things can get very technical
Workflow developers normally consist of Power Users, Information
Workers and Developers
This session is geared more towards Power Users and Information
Workers
Will try to use real life analogies as much as possible
8
10. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
10
SM
Then you are at the right session …
Generally we get fixed set of actions/activities
We have to work around those fixed set of tools to
achieve our business requirements
Analogy : Workflow development is quite similar to
using Public Transportation
• Especially workflow testing
To reach to a particular destination, we have to use
the transportation modes (Train/Bus/Flight etc.)
If our destination is not on the predefined route,
we need to use additional/supplement mode of
transportation like Phone a friend, Taxi , Uber or
Lyft
10
http://usdotblog.typepad.com/secretarysblog/2010/03/public-transportation-in-the-spotlight.html#.WKHE5zvyuwU
11. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
11
SM
Then you are at the right session …
Using REST APIs in workflows is like
using additional/supplement mode of
transportation like Uber or Lyft to reach
your destination.
Caution : REST APIs may or may not
help you to solve all the business
requirements
Before talking about REST APIs let’s dive
into some basics
11
13. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
13
SM
With SharePoint 2013 Microsoft released a new product called “Workflow Manager”
SharePoint 2013 style Workflows are built using Workflow Foundation 4.5 and run out of SharePoint
Workflow is separate server Product called Workflow manager and is not part of SharePoint
Infrastructure
Communication between Workflow manager and client (SharePoint) occurs using REST API and Oauth
SharePoint 2013 style Workflows are fully Declarative
SP2013 workflows are no longer compiled into .NET assemblies instead XAML files defines workflow
and their execution
No more custom code
Workflow Manager Architecture
14. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
14
SM
High Level Architecture of Workflow Infrastructure
14
15. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
15
SM
Generally during workflows development we have to work with limited set of actions/tools
SharePoint Designer 2013 is the last version and there will be no new actions/activities get added
Because of Web Service Call, we are not limited to just the activities provided by the SharePoint
Designer 2013/Visual Studio, we can use the REST APis to enhance the workflows.
We can not use Custom Code
Instead, we can write the business logic as REST endpoints and call those endpoints using workflows
Help us to implement complex business requirements
Why we need to use Web Service?
16. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
16
SM
Using “Call to HTTP Web Service” we can use following types of Web
Services in Workflows
Anonymous Web Services
3rd Party REST API
Custom ODATA Services
SharePoint REST APIs
Action : Call HTTP Web Service
18. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
18
SM
REST stands for Representational State Transfer
REST is an architectural style for networked hypermedia applications
REST is used to build Web services that are lightweight, maintainable, and scalable
REST is not dependent on any protocol, but almost every RESTful service uses HTTP as its underlying
protocol
What is REST?
19. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
19
SM
SharePoint REST Service Architecture
19
If you want to do
this to an
endpoint
Use this
HTTP
request
Keep in Mind
Read a resource GET
Create or update
a resource
POST • Use POST to create entities such as lists and
sites.
• For POST operations, any properties that are not
required are set to their default values.
Update or insert a
resource
PUT • Use PUT and MERGE operations to update
existing SharePoint objects.
Delete a resource DELETE • Use the HTTP DELETE command against the
specific endpoint URL to delete the SharePoint
object represented by that endpoint.
• In the case of recyclable objects, such as lists,
files, and list items, this results in a Recycle
operation.
Odata : Open Data Protocol
JSON : JavaScript Object Notations
20. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
20
SM
20
•
Action - Call HTTP Web Service
21. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
21
SM
We can impersonate the user in SharePoint 2010 style workflows. This option is not available in
SharePoint 2013 style workflows.
Be default, workflow run under the initiator's context.
To grant higher level access level to the workflow
Configure the workflow to run as an App
This is an additional configuration step we have to do outside of the workflows.
Workflows running as apps can be assigned specific elevated permissions.
User Identity in SharePoint Online Workflows
22. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
22
SM
If App Step is not Pre-Configured..
23. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
23
SM
Site Actions -> Manage Site Features ->Activate the feature
Site Feature “Workflows can use app permissions”
Site Actions -> Site App Permissions -> Copy the GUID of the
App “Workflow”
i:0i.t|ms.sp.ext|e7c41053-58d2-4cd9-98d3-
7aa16b7e41b2@f4d429d6-cf67-43c7-84e4-943fdcb4e663
Go to siteUrl/_layouts/15/appinv.aspx page
Paste the Workflow App GUID in the App ID box and click
lookup
Enter App's Permission Request XML
<AppPermissionRequests>
<AppPermissionRequest
Scope="http://sharepoint/content/sitecollection/web"
Right="FullControl" />
</AppPermissionRequests>
How to configure
the App Step?
https://msdn.microsoft.com/en-us/library/office/jj822159.aspx
24. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
24
SM
Trust the App by clicking on “Trust it”
Open the SharePoint Designer and try to add the App Step
Wish the steps were simple…
• If you don’t have access, work with administrator
How to configure
the App Step?
https://msdn.microsoft.com/en-us/library/office/jj822159.aspx
25. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
25
SM
Typical Steps you should follow while using REST
APIs
Test REST End
Point
• Test the REST endpoint outside of the workflow using tool of your
choice like Postman, Fiddler, Console Application or JavaScript etc.
Implement • Implement the REST API in the workflow
Test the
workflow
• Test the workflow
Check First
• Check if the action is already available
28. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
28
SM
Naming Convention for Custom Workflows
•
•
Create new tasks list and history lists for each workflows and try to avoid using the OTTB history list and
workflow tasks list
•
•
•
In the code log to the history list the url/site that we are going to hit
Don’t create the variable if you don’t have to
•
Before using the REST APIs in the Workflow, to save the time, use other method of your choice to make
sure the API calls are working. Like Visual Studio Console Application, JavaScript, Fiddler, PostMan etc.
Tips and Best Practices
29. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
29
SM
In Office 365 workflow manager has strict throttling limits for SharePoint
2013 Style workflows
The instance has exceeded the outbound http request quota for a 1.00:00:00
time period. The 5000 request limit was reached in <time>.
•
Workflow instances can get suspended and we need to wait 24 hours to
resume the suspended workflow instance by
•
•
•
Throttling in SharePoint Online Workflows
31. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
31
SM
There is no OOTB email alert if the workflow get
suspended
We can find the suspended workflows on the page
/_layouts/15/WorkflowServiceHealth.aspx
If we develop workflow as an “App” these throttling
limitations does not apply
•
Throttling in SharePoint Online Workflows
32. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
32
SM
Avoid infinite loops
We may use “Wait for field change in current item”
Avoid using a workflow to execute complex algorithms
Workflows are intended to manage document-driven, human
processes and not to dispatch significant computational tasks.
Avoid the use of the “Wait for Event in List Item" activity
Throttling in SharePoint Online Workflows
34. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
34
SM
https://msdn.microsoft.com/en-us/library/office/jj163181.aspx
https://msdn.microsoft.com/en-us/library/office/fp142380.aspx
https://msdn.microsoft.com/en-us/library/office/jj822159.aspx
https://support.microsoft.com/en-us/help/3076399/sharepoint-2013-workflow-throttling-and-performance-in-
sharepoint-online-and-project-online
http://www.slideshare.net/pgbhoyar/how-to-develop-maintainable-custom-workflows-in-office365-sharepoint-
online-20160628new-jersey-sharepoint-user-group-63617565
http://rest.elkstein.org/2008/02/what-is-rest.html
https://app.pluralsight.com/library/courses/sharepoint-2013-workflow-web-services/table-of-contents
•
Resources
35. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
35
SM
Recap
• Architecture of Workflow Manager
• Introduction to SharePoint REST APIs
• How to use SharePoint REST API in SharePoint Workflows?
• Demo
• Tips & Best Practices
• Key Takeaways
• Q&A
36. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
36
SM
Key Takeaways
Hopefully the contents we covered today made you to explore
REST APIs and you will go home and play with it
Sign up for Developer Program using https://dev.office.com/
38. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
38
SM
38
How to get Personal Office 365
Development Tenant?
Sign up for Office 365 Developer
Program at http://dev.office.com/
Get 1 year of Office 365 subscription for
free
Excellent for personal development use
1 Month Trial
https://products.office.com/en-
us/business/compare-office-365-for-
business-plans
40. WithumSmith+Brown, PC | BE IN A POSITION OF STRENGTH
40
SM
Questions? Feedback? Contact me:
Email: pgbhoyar@gmail.com
Twitter: @PGBhoyar
Blog: http://pgbhoyar.com
LinkedIn: https://www.linkedin.com/in/pgbhoyar
Slides: https://www.slideshare.net/pgbhoyar
Feedback : Please provide feedback
Email or
Anonymous Suggestions: https://www.suggestionox.com/r/pgb
Thank You
Organizers, Sponsors and You for Making this Possible.