Demonstration of creating custom REST APIs using Azure Functions that may be consumed by workflow applications such as Nintex Workflow Cloud and Microsoft Flow. Shows how to create a custom, but reusable workflow action (Connector) that workflow designers can embed in their workflows.
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Developing Azure Functions for Flow and Nintex SPS SD 2018
1.
2. Developing Azure Functions to create
custom connectors for Microsoft Flow,
PowerApps and Nintex
Tom Castiglia
ShareSquared
3. AboutTom Castiglia…
SharePoint / Office 365
Consultant
Speaker at various
SharePoint
Saturday
conferences
President of the
San Diego
SharePointUser
Group
Nintex vTE
(virtualTechnical
Evangelist)
@TomCastiglia
linkedin.com/in/tomcastiglia
slideshare.net/tomcastiglia
tom.castiglia@sharesquared.com
meetup.com/sanspug/
meetup.com/nintexSD/
https://www.sharesquared.com
4. Today’s Agenda
Overview
•Azure Functions
Overview
•REST Services -
Open API /
Swagger
Development
•Visual Studio 2017
•Sample Project –
Requirements
•Example Code
•Debugging
Azure
Configuration
•Azure Function
App
•Swagger Definition
Connector
Configuration
•Flow / PowerApps
•Nintex Workflow
Cloud
QuickWorkflow
demos in Flow
& Nintex using
custom
connectors
6. Azure Functions - Overview
Build apps faster with a serverless architecture
Accelerate your development with an event-driven, serverless compute
experience. Scale on demand and pay only for the resources you
consume.
Manage your apps instead of infrastructure
Don’t worry about provisioning and maintaining servers, especially when
your workload grows. Functions provides a fully managed compute
platform with high reliability and security and they scale on demand.
7. Azure Functions - Overview
Develop your way
• Languages: JavaScript, C#, and F#, and scripting options such as
Python, PHP, Bash, Batch, and PowerShell.
• Code directly in Azure portal
-- OR --
• Code in Visual Studio 2017 15.3 or later (Still in preview)
• Install “Azure Development” workload
• Includes tooling to create Azure Function projects and classes locally and
publish
• Includes Azure CLI (Command Line Interface) which allow you to run and debug
your functional locally.
8. Azure Functions - Pricing
Azure Functions consumption plan is billed based on per-second resource
consumption and executions. Consumption plan pricing includes a monthly
free grant of 1 million requests and 400,000 GB-s of resource consumption
per month.
METER PRICE FREE GRANT
(PER MONTH)
ExecutionTime* $0.000016/GB-s 400,000 GB-s
Total Executions* $0.20 per million 1 million
*Free grants apply to paid, consumption subscriptions only.
10. OpenAPI (Swagger) Overview
•When you publish an Azure Function, it creates a
REST endpoint for your function.
•OpenAPI allows you to configure the details of
your endpoint
• URL
• HTTP Methods (GET, POST, PUT, etc.)
• Inputs
• Outputs
11. OpenAPI (Swagger) Overview
•It’s a JSON file
•Configured using “YAML”…
• “a human friendly data serialization standard for all
programming languages.”
• “YAML Ain't Markup Language”
•Used by MS Flow and Nintex to import your
function as a new custom connector / action
•Help available at https://swagger.io
13. GSA PerDiem API
• Common workflow use cases areTravel Authorization Requests and
Expense reports, where employees travel and incur expenses for Meals and
Hotels.
• The GSA publishes official “PerDiems” that dictate the maximum amounts
that are may be expensed for Hotels and Meals.
• The PerDiem amounts are updated each year.
• Each region has its own per diems (e.g. Hotels in NYC cost more than in Des Moine)
• PerDiems also vary by month, based on peak travel seasons.
• Public web site: https://www.gsa.gov/travel/plan-book/per-diem-rates
• Often Government employees are trained to manually look up their Per Diems for
each trip prior to submitting expense reports (or better yet, before booking their
hotels)
14. GSA PerDiem API
REST API:
https://www.gsa.gov/technology/government-it-initiatives/digital-
strategy/per-diem-apis/api-for-per-diem-rates
• FiscalYear and Zip
https://inventory.data.gov/api/action/datastore_search?resource_id=8ea44
bc4-22ba-4386-b84c-
1494ab28964b&filters={"FiscalYear":"2017","Zip":“92131"}
• FiscalYear and County
https://inventory.data.gov/api/action/datastore_search?resource_id=8ea44
bc4-22ba-4386-b84c-
1494ab28964b&filters={"FiscalYear":"2017","County":"Worcester"}
15. Sample Response (abbreviated)
• The “Records” element is nested
within a bunch of stuff that can
be ignored
• The element for each month
represents the Hotel PerDiem for
that month.
• The “Meals” element represents
the PerDiem allowed for meals
for the year.
16. UsingVisual Studio
• New Project>Visual
C#>Cloud>Azure
Functions
• “Azure Functions”
maps to a “Function
App”, which can
contain 1 – N individual
functions
• Right-click the project
and select Publish
• Create new Azure
Function App. Then
click Publish.
17. Function App
• Log into Azure Portal to
review new Function App
• Notice it does not contain
any functions yet
• InVisual Studio, Right-
Click the Project and click
Add > New Azure
Function
• Name the function and
click Add
• Select function type as
HttpTrigger and click OK
19. GSA Per DiemWrapper
Accept Zipcode
andTripdate in
JSON as input
(in body of
request)
Validate inputs
Format REST
call to GSA API
Format JSON
response with
GSA per diem
amounts (Hotel
and Meals)
27. Export to Flow & Power Apps
Express
• Easier
• Use this if your Function App is in the same tenant as
your Flow / Office 365 AAD
Manual
• A few extra steps
• use this if yourAzure Function App is in a separate
Azure tenant.
34. Thank You to Our Sponsors
PLATINUM
GOLD
SILVER BRONZE
35. Join us right after at The Urge
Bocce Ball, Cornhole and Bowling!
Urge Gastropub & Common House
(practically across the street)
255 Redel Road, San Marcos, CA 92078
https://sm.urgegastropub.com/
Thank you for joining us today!
Don’t Forget SharePint
Notes de l'éditeur
This session will make use of these technologies, but I won’t spend much time explaining them, as I assume you’ve at least dabbled in MS Flow and have done some development in Visual Studio.
Fair warning … this is the most complex part of the process. Troubleshooting is tricky. We could easily spend an hour on this alone, but we’ll have to skim over this part later. There are
Fair warning … this is the most complex part of the process. Troubleshooting is tricky. We could easily spend an hour on this alone, but we’ll have to skim over this part later. There are
All the Azure function tutorials that I found were really simplistic, using the GET method and passing params in the URL querystring. But systems like MS Flow, PowerApps and Nintex send and receive data in JSON format. So I needed to come up with a more realistic sample. I also wanted something that would make sense in the context of a workflow solution.
Visual Studio provides excellent support for serializing / deserializing between JSON. Also can auto-generate new classes from existing JSON, using the Paste Special menu under Edit.
The CreateResponse method automatically serializes the PerDiemOutput class into JSON.
If we enable additional methods that aren’t needed the API definition (next step) will be more complex, so its best to limit to just POST.
Select the Function App > Platform Features > API Definition
Click Generate API Definition template
Edit the API Definition
Save
Select Express
Select Environment
Enter friendly name for the Custom API that will be displayed in Flow / Power Apps
If using API Key, enter the friendly label that shall be displayed in Flow when a user creates a unique connection using the connector. For example, provide email address for Azure admin who has the API KEYS.
Click OK
From Flow.Microsoft.com, click the gear icon > Custom Connectors
Locate the desired connector, then click the plus (+) sign for that connector
This will display a dialog to enter the API KEY
Locate
Click Xtensions then the Plus (+) sign
Copy/Paste the API Definition Url including the key (from Azure portal). Then click Next.
Accept default settings on the Security page. Then click Next.
Specify a friendly Name and Description for the connector. Select an icon or upload a custom icon. Then click Save.
Click Connections > Add New
Select the DocFluix Demo App from the Connector list, then click Connect
Give the new connection a friendly name (e.g. DocFluix Demo) and paste in the API Key, the click Connect
Verify the connection is created successfully, then click Ok