Post

Receive Microsoft 365 Service Announcements in Teams using Power Automate

How to receive Microsoft 365 Service Announcements in Teams using Power Automate

Introduction

Here I am, my very first post on my blog. I hope you will enjoy reading it as much as I enjoyed writing it.

As an IT professional, I am always looking for ways to automate tasks. In this post, I will show you how to receive Microsoft 365 Service Announcements in Teams using Power Automate. We will create an app registration in Entra ID and use the Microsoft Graph API to get the service announcements using Power Automate. Then we will send the service announcements to a Teams chat on a daily basis.

Prerequisites

  • Microsoft 365 subscription
  • Power Automate Premium license

You need a Power Automate Premium license to use the HTTP action in Power Automate. You can get a Power Automate Plan 2 trial license for 90 days to get started. I will show you how to get the trial license later in this post.

Step 1: Create an app registration in Entra ID

  1. Go to the Entra ID portal and sign in.
  2. Click on App registrations in the left menu in the submenu Applications.
  3. Click on New registration.

    Desktop View

  4. Enter a name for the app registration, select Accounts in this organizational directory only, and click on Register.

    Desktop View

  5. Click on API permissions in the left menu.
  6. Click on Add a permission.
  7. Select Microsoft Graph.
  8. Select Application permissions.
  9. Search for ServiceMessage.Read.All and select it.
  10. Click on Add permissions.

    Desktop View

  11. Click on Grant admin consent for {your organization}.

    Desktop View

  12. Click on Certificates & secrets in the left menu.
  13. Click on New client secret.
  14. Enter a description for the client secret, select an expiration date, and click on Add.

    Desktop View

  15. Copy the Secret value and save it in a secure location.
  16. Click on Overview in the left menu.
  17. Copy the Application (client) ID and Directory (tenant) ID and save them in a secure location as well, we will need them later.

    Desktop View

Step 2: Create a Power Automate flow and set variables

  1. Go to the Power Automate portal and sign in.
  2. Click on My flows in the left menu.
  3. Click on New flow and select Scheduled cloud flow.

    Desktop View

  4. Enter a name for the flow and click on Create, we will finetune the frequency in the next step.

    Desktop View

  5. Click on Recurrence and set the frequency to Daily by selecting Interval: 1 and Frequency: Day.

    Desktop View

  6. Now we will set the app_id, client_secret, and tenant_id as variables. Click on the + icon below the recurrence trigger to add an action.
  7. Search for variable and select Initialize variable.

    Desktop View

  8. Enter app_id as the Name and the Application (client) ID from the app registration in Entra ID as the Value. Click on Create.

    Desktop View

  9. Repeat the previous steps (6-8) to add the client_secret and tenant_id as variables.

Only use this approach for testing purposes. It is not recommended to store sensitive information in plain text. You should use a Key Vault or a secure storage solution to store the client secret. To do this, follow the steps in the Microsoft documentation.

  1. The flow should look like this:

    Desktop View

Step 3: Get an access token

  1. Add an action below the last Initialize variable action by clicking on the + icon.
  2. Search for HTTP and select HTTP.

    Desktop View

  3. Enter the following information:

    • Uri: https://login.microsoftonline.com/@{variables('tenant_id')}/oauth2/v2.0/token
    • Method: POST
    • Headers:
      • Content-Type: application/x-www-form-urlencoded
    • Body: client_id=@{variables('app_id')}&client_secret=@{variables('client_secret')}&grant_type=client_credentials&scope=https://graph.microsoft.com/.default

    Desktop View

(Optional) Get a Power Automate Plan 2 trial license

  1. Click on Save after adding the http-action.

When there’s no Power Automate license available, you will get a pop-up message to upgrade your license. Click on Sign up for a free 90-day trial: Desktop View Then click on Start trial to get a Power Automate Plan 2 trial license for 90 days. Desktop View

Step 4: Parse the Access Token JSON response

To get the access token, we need to parse the JSON response from the HTTP action. We will use the Parse JSON action to do this. To parse the JSON response, we need to know the schema of the JSON response. We can get the schema by sending a test request to the URI and copying the JSON response.

  1. Save the flow.
  2. Click on Test, select Manually and click Test and Run Flow to send a test request to the URI.

    Desktop View

When you run the flow for the first time after starting the trial, you will get a pop-up message that the flow is disabled.

Close the flow by clicking in the top left corner and turn the flow on by clicking on the Turn on button. Desktop View

{start=”3”}

  1. Go to the Flow Runs Page by clicking the link and open the latest run.

    Desktop View

  2. Click on the HTTP action to see the details of the action and copy the JSON response from the Body to your clipboard.

    Desktop View

  3. Click on Edit to go back to the flow.
  4. Add an action below the HTTP action by clicking on the + icon.
  5. Search for parse json and select Parse JSON.

    Desktop View

  6. Click on the lightning bolt icon in the Content field and select Body from the HTTP action.

    Desktop View

  7. Click on Use sample payload to generate schema and paste the JSON response from the HTTP action. Click on Done.

    Desktop View

This is how the Parse JSON action should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
    "type": "object",
    "properties": {
        "token_type": {
            "type": "string"
        },
        "expires_in": {
            "type": "integer"
        },
        "ext_expires_in": {
            "type": "integer"
        },
        "access_token": {
            "type": "string"
        }
    }
}

Step 5: Get the service announcements

Now that we have the access token, we can use it to get the service announcements from the Microsoft Graph API. We will use the HTTP action to get the service announcements.

  1. Add an action below the Parse JSON action by clicking on the + icon.
  2. Search for HTTP and select HTTP.

    Desktop View

  3. Enter the following information:

    • Uri: https://graph.microsoft.com/v1.0/admin/serviceAnnouncement/messages
    • Method: GET
    • Headers:
      • Authorization: Bearer @{body('Parse_JSON')?['access_token']}
    • Queries:
      • $select: id,category,severity,tags,title,category,startdatetime,enddatetime,services,details,body
      • $orderby: startDateTime desc

    Desktop View

We will add the $filter query parameter to filter the service announcements by the startDateTime in the next step, because we need a filled JSON to generate the schema for the Parse JSON action.

Step 6: Parse the Service Announcements JSON response

  1. Save the flow and Test it to get the service announcements.
  2. Go to the Flow Runs Page by clicking the link and open the latest run.
  3. Click on the HTTP-action Get Service Announcements to see the details of the action and download the JSON response from the Outputs, copy the file to your clipboard. Desktop View
  4. Click on Edit to go back to the flow.
  5. Add an action below the Get Service Announcements action by clicking on the + icon.
  6. Search for parse json and select Parse JSON.

    Desktop View

  7. Click on the lightning bolt icon in the Content field and select Body from the Get Service Announcements action.

    Desktop View

  8. Click on Use sample payload to generate schema and paste the JSON response from the Get Service Announcements action. Click on Done.

    Desktop View

This is how the Parse JSON action should look like: Desktop View

Step 7: Filter the service announcements

Now that we have the schema for the service announcements, we can filter the service announcements by the startDateTime. We will use the Filter array action to do this.

  1. Open the Get Service Announcements action.
  2. Under Queries, add the following query parameter:
    • $filter: startDateTime ge @{formatDateTime(utcNow(), 'yyyy-MM-dd')}

    Desktop View

  3. Leave the rest of the action as it is.

Step 8: Select neccessary columns and create a HTML table

  1. Add a new action by clicking on the + icon.
  2. Search for Select and select Select.

    Desktop View

  3. Click on the From field and select value.

There’s a bug in Power Automate that doesn’t show value in the From field-selector. By selecting Body value, you get a “NULL” output value. This is because we need to select “@body(‘Parse_JSON_1’)?[‘value’]”, instead of “@body(‘Parse_JSON_1’)?[‘body’]?[‘value’]”. You need to copy paste this value in the From field: @body('Parse_JSON_1')?['value'].

  1. Click on Map and enter the following information:
NameValue
ID@item()?['id']
Title@item()?['title']
Category@item()?['category']
Start@item()?['startDateTime']
Services@join(item()?['services'],', ')

{start=”5”}

  1. It should look like this:

    Desktop View

  2. Add a new action by clicking on the + icon.
  3. Search for Create HTML table and select Create HTML table.

    Desktop View

  4. Click on the From field and select Output from the Select action. Leave the rest of the action as it is. Desktop View

Step 9: Send the service announcements to a Teams chat

  1. Add a new action by clicking on the + icon.
  2. Search for teams chat and select Post message in a chat or channel.

    Desktop View

  3. Click on Sign in and sign in with your Teams account to create the connection to Microsoft Teams. Desktop View

  4. Fill in the following information:
    • Post as: Flow bot
    • Post In: Chat with Flow bot
    • Recipient: Your own email address
    • Message: @{outputs('Create_HTML_table')}

    Desktop View

Step 10: Save and test the flow

  1. Save the flow.
  2. Click on Test and select Manually and click Test and Run Flow to test the flow. You should see only green checkmarks if everything is configured correctly:

    Desktop View

You should now receive a message in your Teams chat with the service announcements from your test.

Conclusion

Congratulations, you have successfully created a flow to receive Microsoft 365 Service Announcements in Teams using Power Automate!

This was only an idea of how you can use Power Automate, combined with the Microsoft Graph API, to automate tasks. You can now customize the flow to fit your needs, for example, by adding a condition to only send the service announcements if there are any new announcements.

I know this was a long post, but I hope you enjoyed it. If you have any questions or feedback, feel free to leave a comment below. I would love to hear from you!