Exercise: Creating a Custom Connector

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

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

  1. No one outside of Communications can have the credentials to log into the social media accounts
  2. 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

  1. 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.
  2. Enter the following payload:
    {
    "tweet":"this is my tweet",
    "requestedby":"mattweston365"
    }
    Press done when ready.
  3. 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

  1. Add a "Start  an Approval" action to your Flow
  2. 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:
  3. 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?

  1. 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.
  2. If the condition is true: add an action to "Post a tweet"
  3. If the condition is false: either do nothing or place a Terminate control

Step 2 - Custom Connector

  1. Navigate back to the Flow home page, select the Data dropdown, and select Custom connectors
  2. In the top right, select "+ Create custom connector" and "Create from Blank"
  3. Give the connector the name "Company Social Media"
  4. If you wish to supply a custom icon and colour please feel free
  5. In the host field, paste in the first part of the request url
  6. In the base URL, paste in the remaining static elements of the request url
  7. In the breadcrumb at the top, click Definition
  8. Under actions, click New Action
  9. In the Summary field, supply the friendly name for your action i.e. "Post to Social Media"
  10. In the description put in a little bit more information
  11. In the operation ID add the unique name for your operation i.e. "PostToSocialMedia"
  12. Under Request, select "Import from Sample"
    1. Select the verb as "Post"
    2. Paste the full request URL from your Flow in Step 1 into the URL
    3. Provide an example JSON body e.g.:
      {
      "tweet":"My test tweet",
      "requestedby":"MattWeston365"
      }
    4. Click Import
  13. For each of the elements now created in Query, click on them and perform the following actions:

    1. Make them required
    2. Make them internal (this will mean that the users won't be able to change the value)
    3. Provide a default value for each from the Flow request querystring
  14. Under response, click "Add default response"
    1. Enter an example JSON body e.g.
      {
      "response":"All Good"
      }
  15. 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"

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.


  1. Add a new action
  2. Use the filters just below the search box to filter to Custom Connectors
  3. Select your custom connector
  4. Complete the required information by selecting the relevant fields from our trigger
  5. 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