Call Office 365 Service Communications API and Return New Service Health Notices – Part 3

Here is how I have managed to return the latest Service Health alert (only) from Office 365 "Office 365 Service Communications API".

Office 365 New Service Alert Email

As any O365 admin will know, Microsoft won't offer an inbuilt alert that will notify you by email when a new Incident arises so here is how I have chosen to get round that and here is a sneak peek of the output:

Firstly, we will need to register an app in Azure AD. Please see Register an App in the Azure Active Directory for instructions on how to do that.

Once we have the TenantID, ClientID and SecretID and our app has the required permissions, we are ready to build our Flow.

Start by locating the pre-made Microsoft template called Email me a weekly summary of Office 365 message center notices.

Configure your connectors as below:

Now name your flow and let's get to modifying it.

Would you like to buy Alan a coffee?

Visit the AlanPs1 Ko-fi page

Just below the Recurrence trigger, hover over the + sign and insert a new step.

Add 3 x Initialize Variable.

Name them Initialize TenantID variableInitialize TenantID variableInitialize TenantID variable respectively.

Now let's set the Recurrence to every 10 minutes and load our variables with the data we generated from the Azure App.

Note: Clearly, I am from the UK and have set my timezone to suit but please set yours to suit.

Also, there is no need for a Start time but having one means the Flow runs like clock work and delivers data at exactly 9:10am, 9:20am, 9:30am etc.

The template will then call Get Access Token to retrieve a bearer token, which will be used in a subsequent call to the services communication endpoint.{variables('TenantID')}/oauth2/token


The template will then parse the token, and ultimately call a GET method in the Office 365 Service Communications API endpoint within Get Office 365 messages below.

Just in case you have an issue generating the schema for Parse JSON then it is listed below:

    "type": "object",
    "properties": {
        "token_type": {
            "type": "string"
        "expires_in": {
            "type": "string"
        "ext_expires_in": {
            "type": "string"
        "expires_on": {
            "type": "string"
        "not_before": {
            "type": "string"
        "resource": {
            "type": "string"
        "access_token": {
            "type": "string"

Parse JSON calls the body of the Get Access Token HTTP request in order to gather the access token.

Get Office 365 messages then using the access token to call your own relevant URI in the following format.<domain>/ServiceComms/Messages/api/v1.0/<tenant>

The following  takes the data from Get Office 365 messages, looks for only MessageType not equal to Restoring Service and with a StartDate of 10 minutes ago or less.

No we are starting to work with the data that has been returned by the request.



1b. Build schema using "Use sample payload to generate schema" with JSON from previous step.




@and(not(equals(item()?['Status'], 'Restoring Service')))




@greaterOrEquals(item()?['StartTime'], addminutes(utcnow(), -10))

Now, before we create an HTML table we will need to know if the previous request and it's filters have any data.



NB: If there is no new incidents in the last 10 minutes this Flow will complete as a success but with no email output.

EDIT (Step 4): 6th February 2019 –

When there has been data returned the following will create an HTML table:


















formatDateTime(item()['LastUpdatedTime'],'dd-MM-yyyy HH:mm:ss')


formatDateTime(item()['StartTime'],'dd-MM-yyyy HH:mm:ss')

Now time to send the email, but I prefer to link an Office 365 Profile first

And here is what I have added to my HTML Email (See advanced options)


formatDateTime(utcNow(),'dd/MM/yyyy | HH:mm')




         table {
         border-collapse: collapse;
         width: 100%;
         text-align: center;
         td, th {
         border: 1px solid #ddd;
         padding: 4px;
         th {
         padding-top: 8px;
         padding-bottom: 8px;
         background-color: #7F7D7E;
         color: white;
         font-weight: normal;
      <span style="display:none">
      Attention! You have a live O365 Incident. Just Landed! ...
      <img src="#" alt="Text" height="100" width="114">
      <span>Click <a href="">here</a> to visit the Service Health Dashboard</span>

As a foot note, I can spot one or 2 ways that could enhance or improve this Flow. You may be able to also. If you feel you would like to offer an improvement then please do not hesitate to let both myself and the community know by posting below and if you have any questions please ask away and I will do my best to answer.


Part 4 >>>


This blog is an enhancement of this extremely helpful blog post

Credit to Antonio Maio for the content in that post.

Do you need assistance building this Flow?


Visit the Get Help section of the Power Automate Community