Power Community

Power Community

Subscribe to Microsoft Graph using Power Automate

Subscribe to Microsoft Graph API using Power Automate

In my series about the Graph API, I’m going to look at subscribe to ‘things’ to trigger a flow when events happen using Microsoft Graph in Power Automate.

Subscriptions

Using the subscription model it is possible to subscribe to any changes in on of the following:

  • Call Records
  • Channels
  • Chat
  • Chat Message
  • Contact
  • Conversation Members
  • Drive Item
  • Events
  • Groups
  • Group Conversation
  • Lists
  • Messages
  • Presence
  • Printers
  • Print Task Definition
  • Security Alert
  • Teams
  • To Do Tasks
  • Users

When you subscribe you can with different change types:

  • created
  • updated
  • deleted

Using these change types you can for example only trigger flows when an event is updated, deleted or created or a combination of these operation.

Subscribe using Power Automate

We are going to create two flows. A subscription flow that we run on a daily basis and a flow that we want to run to handle the process that we want to trigger.

This should result in a flow that looks like this:

Subscribe to Microsoft Graph API

In the above example I’m subscribing to CallRecords that are created or updated.

For each subscription you have to specify an expiration date. As our flow resubscribes every day, I’m goig to set the subscription expiry time to 1 day after my subscription flow runs. I’m using the following expression for this:

addDays(UtcNow(), 1)

Callback URL

The List Callback URL action will give me the URL of the flow that I want to trigger when a new call comes in.

This matches the URL that is given by the When a HTTP request is received action of my flow that is being triggered every time a Call record is created or updated.

Subscribe to Microsoft Graph using Power Automate Microsoft Office 365 image 33

Subscription URIs

So for each different thing that we might want to subscribe to a specific UTI will need to be supplied. For Call records this is /communications/callRecords, but there are various options depending on what you want to subscribe to.

Handle the changes

Now we need to create a second flow. This flow will be triggered every time a change is made. So in our example every time a call is made our flow will trigger. Notice that this flow will also trigger when we subscribe.

Subscribe to Microsoft Graph using Power Automate Microsoft Office 365 image 34

The trigger will need to have a schema specified that looks like this:

{
    "type": "object",
    "properties": {
        "validationToken": {
            "type": "string"
        }
    }
}

And the validation token can now be used to see if we have ouor flow triggered because of the initial subscription or if this is a call record update trigger triggering our flow.

Then we need to respond back to the parent flow with a success code (200) to acknowledge that we have received the subscription. We also need to acknowledge any other triggers of our flow. After this acknowledgement you can now use the data that is supplied by the trigger of our flow. So in our example you will see that you get actual call records.

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Integrating Dynamic 365 CRM with Third party API via custom connector using Power Automate – Part2

Integrating Dynamic 365 CRM with Third party API via custom connector using Power Automate – Part2 This article is in...

More Articles Like This

- Advertisement -spot_img