Tuesday 14 November 2017

Using Webhooks for Posting SharePoint Items into MS Teams with Flows

In my previous post, you would have seen posting the items into Microsoft Teams Channels as conversations using Microsoft Flows. The respective channels will be chosen by selecting the Teams service in the flow configurations.

In this post, let us try to achieve similar kind of functionality, but with a little different approach. As we are all aware that Microsoft Teams will support incoming webhook requests, let us try configuring the webhook URLs.


Webhook:


What is webhook? The external system which posts messages whenever data is available using the endpoint APIs.


How the webhook will help in Microsoft Teams? Take for an example, you are using Teams as a collaboration platform. You need to post data from multiple systems to the team channels for better collaboration. The webhook URL can be generated for a channel and can be shared with other external systems. Whenever the external system has the data for posting, the data will be sent to the teams using the API generated.



Creating Webhook:


First, try creating the webhook URL in the Microsoft Teams portal.
  • Navigate to the respective channel under the teams.
  • Next to the channel, click on the dots. You could find the connectors.
  • Click configure option, provide the name and upload image (optional) for the webhook.
  • Once created, the webhook URL will be displayed on the popup screen. You can copy this for later use.


Note: The webhook URL can be shared with any other external system to receive the data. In this case, the configuration happens using Microsoft Flow’s HTTP post option. Alternatively, azure logic app or any other approach can be used.


Configure Flow:


  • Login to flow.microsoft.com portal.
  • From my flows, create a new flow from the blank template.
    • The trigger will be “when an item is created” on SharePoint.
    • Configure the site and list details.
  • Add an action. Select HTTP connector and then chose HTTP action.
    • Chose method as post.
    • Uri with the webhook URL generated above.
    • And body with appropriate JSON text. In this case, SharePoint item title will be used.
  •  Save the flow.



Test:


Go to the respective SharePoint list and create a new item. Once created, the item will be posted on to the respective Team channel.


This flow can be monitored from the flows portal.