This exercise is intended to be a companion to the presentation: "Custom Connectors - The Key to Unlocking the Universe?" This is a practical guide to creating a sub-Flow with a Custom Connector to demonstrate how custom connectors can bring value to your organisation. To follow this exercise, I am assuming that you have a basic understanding of how to use Microsoft Flow, therefore the steps only direct which actions to use rather than step by step guide on how to add them.
Please be aware, that if you're following this guide AFTER the 1st February 2019, you will need a Flow P1 or Flow P2 license to allow the creation of custom connectors. Further details can be found here:
https://techcommunity.microsoft.com/t5/Office-Retirement-Blog/UPDATED-Updates-to-Microsoft-Flow-and-PowerApps-for-Office-365/ba-p/289589
Please be aware, that if you're following this guide AFTER the 1st February 2019, you will need a Flow P1 or Flow P2 license to allow the creation of custom connectors. Further details can be found here:
https://techcommunity.microsoft.com/t5/Office-Retirement-Blog/UPDATED-Updates-to-Microsoft-Flow-and-PowerApps-for-Office-365/ba-p/289589
Scenario
We work for Contoso LTD, a company which actively promotes its departments to push stories out via social media. The social media accounts are controlled exclusively by the Communications Team who have two main rules- No one outside of Communications can have the credentials to log into the social media accounts
- All communications must go through approval by the Communications Team before being published
The first department who want to make the most of this service being offered by Communications, is the HR department who want to use it to promote new joiners to the business on Social Media.
Solution
The solution which we will implement will be a Flow which is owned by members of the communications team. This will incorporate an Approval, and if the post is approved it will be posted to Twitter. A Custom Connector will be created to allow other areas of Contoso LTD to post to social media through the control mechanisms required by Communications.
Step by Step
Step 1 - Communications Flow
The communications Flow will be a simple Flow which is triggered by a HTTP request, will call for an Approval based on the inputs, and then will post to a social media account of your choice. For the purpose of this exercise, I will refer to Twitter.
Trigger - When a HTTP Request is Received
- When you add a "When a HTTP Request is Received" trigger, it will generate a request URL the first time you save, so don't worry that it's not there straight away. What I am interested in is the Body schema, and I'm going to make this easy on myself by using the "Use sample payload to generate schema" link. Click the link.
- Enter the following payload:
{
"tweet":"this is my tweet",
"requestedby":"mattweston365"
}
Press done when ready. - Save your Flow now to generate the request URL, and then ensure you have this to hand for when we create the custom connector
Action - Start an Approval
- Add a "Start an Approval" action to your Flow
- Complete the Approval form with all of the required fields. When you're selecting data which is passed into the Trigger, you may need to select to "See more" when looking at the tool box on the right hand side:
- Complete the form, not forgetting to assign the approval to at least one person. Take "requestedby" and the Tweet from the trigger as shown below.
Condition: Has the Tweet been approved?
- Add a new condition, and base that on the "response" from the "Start an Approval" action. If the response is equal to "Approve" then we can post out to Social Media, otherwise we'll terminate and do nothing else.
- If the condition is true: add an action to "Post a tweet"
- If the condition is false: either do nothing or place a Terminate control
Step 2 - Custom Connector
- Navigate back to the Flow home page, select the Data dropdown, and select Custom connectors
- In the top right, select "+ Create custom connector" and "Create from Blank"
- Give the connector the name "Company Social Media"
- If you wish to supply a custom icon and colour please feel free
- In the host field, paste in the first part of the request url
- In the base URL, paste in the remaining static elements of the request url
- In the breadcrumb at the top, click Definition
- Under actions, click New Action
- In the Summary field, supply the friendly name for your action i.e. "Post to Social Media"
- In the description put in a little bit more information
- In the operation ID add the unique name for your operation i.e. "PostToSocialMedia"
- Under Request, select "Import from Sample"
- Select the verb as "Post"
- Paste the full request URL from your Flow in Step 1 into the URL
- Provide an example JSON body e.g.:
{
"tweet":"My test tweet",
"requestedby":"MattWeston365"
} - Click Import
- For each of the elements now created in Query, click on them and perform the following actions:
- Make them required
- Make them internal (this will mean that the users won't be able to change the value)
- Provide a default value for each from the Flow request querystring
- Under response, click "Add default response"
- Click "Create Connector"
We now have a custom connector which, when called, will initiate our Flow.
Step 3 - Consuming Flow
The final step is to create a consuming Flow so that we can see everything come together.
I have created a SharePoint site with a list called "Tweet Bank". This list has a the default Title field and a multi-line text field called "Tweet".
Create a new Flow called "When an item is added to the Tweet Bank"
Create a new Flow called "When an item is added to the Tweet Bank"
Trigger - When an item is added or modified
Action - Post to Social Media
This is where we can now select our custom connector with the relevant action to use in anger.- Add a new action
- Use the filters just below the search box to filter to Custom Connectors
- Select your custom connector
- Complete the required information by selecting the relevant fields from our trigger
- Save the Flow
Conclusion
We now have a number of assets with Office 365 which combine together to form a single solution.
- Social Media Flow - designed to take an input and seek approval before posting out onto Social Media.
- Custom Connector - providing an interface to the Social Media Flow so that other business users can
- SharePoint List - providing an input point for new Tweets to be created
- Consuming Flow - taking the input from the SharePoint list, and passing it through our custom connector to the Social Media Flow
Now go and create an item in your Tweet Bank and observe everything working together to give you a simple solution which showcases how to use a Custom Connector.
Comments
Post a Comment