Start a subscription Flow

Just wanted to share this blog with you guys and it is also for my own reference. I created a Flow to start a subscription for SharePoint on the Office 365 Management Activity API.

Office 365 Management APIs

Lately I have been playing around with the different Office 365 Management APIs. One of them is the Service Communications API. This API is a great to keep an eye on service status and incidents. Lee Ford for instance has a great blog on how to use this API and get the latest service status with Flow or PowerShell.

Subscription to what?

Another API is the Office 365 Management Activity API. This API also has the ability to start a subscription for different content types. Currently these content types are supported:

  • Audit.AzureActiveDirectory
  • Audit.Exchange
  • Audit.SharePoint
  • Audit.General
  • DLP.All

The generic subscription Flow

Instead of using Postman I decided to create a Flow for this. I also made it generic by using some variables for the ContentType, authID and the FlowAddress. The FlowAddress is the most important one. This is the url from another Flow with a When a HTTP request is received trigger.

The Flow uses these variables in the HTTP post action. The URI will be similar to this:
https://manage.office.com/api/v1.0/{TenantID}/activity/feed/subscriptions/start?contentType={ContentType}

Create webhook

In the body of the post we will use the FlowAddress and AuthID variables.

I am also using Active Directory OAuth and a Azure AD application registration for the HTTP post action. There are a lot of nice docs on this subject, one of them is How to set up an Azure AD application registration for calling Microsoft Graph by Laura Kokkarinen.

Monitoring site collection creation

One of the content types is SharePoint, so I decided to start a subscription for Audit.SharePoint. I created a Flow to consume this subscription. This Flow will monitor the creation of site collections in SharePoint and post a message to a Microsoft Teams channel with the details of this activity.

Site Collection Create Message

1. HTTP Request received trigger

The trigger for the Flow is When a HTTP request is received trigger. After you save the Flow you need to copy the HTTP Post Url. You can post this value in the FlowAddress variable of the generic subscription Flow.

Request body json schema

The Flow uses the following Json for the Request body. This part is also described on the Flow blog in the Automate Flow Governance article.

2. Get activity details

After this step we will use contentURI from the incoming activity messages to get the details of every activity. The Flow uses an expression for this.

Get Activity

3. Parse response

The response will be in json format so the Flow also uses a Compose action.
Parse JSON Get activity

This compose action uses the following json schema.

4. Check for Site Collection Operations

In this Flow a condition is being used to check for the SiteCollectionCreated Operation.

Condition Operation Site Collection Created

5. Post a Teams message with details

If an activity is of this type the Flow will post a message to Microsoft Teams with details on who has created the Site.

Post Message Site Collection Created

Run subscription Flow once

In order to start you subscription you need paste the HTTP Post Url in the FlowAddress variable of the generic subscription Flow. After that you can run the subscription Flow once. You should receive a HTTP 200 response with details of the created subscription.

Run generic subscription Flow

After that you can test it by creating a new SharePoint site collection and wait for about 15 minutes.

This is just a quick example. Of course you can monitor other kind of operations like users added to a group. The possibilities are endless. Happy testing!

You may also like...

1 Response

  1. May 16, 2019

    […] I created a Flow to start a subscription for SharePoint on the Office 365 Management Activity API. Today I will share my Flow which lists all the current […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.