Skip to main content
All CollectionsIntegrationsAPI
Workspace API example: SharePoint newsfeed in announcements
Workspace API example: SharePoint newsfeed in announcements
Updated over a week ago

Introduction

You can use Microsoft Power Automate to post information to the Hub in Workspace 365. In this article we will show you how to use a Power Automate flow to generate announcements from news posts in a SharePoint Newsfeed. Check out the Announcement API endpoint for more information.

Power Automate can only access the shortened version of the news post contents. This is called the "Description" and contains the first 250 characters without any form of styling. We can however add a link to the full news post.

Prerequisites

  • An account with access to the SharePoint site.

  • A Power Automate Premium license (tip: Microsoft offers a free 90-day trial license).

  • An enabled API key for the Announcements API. You can have multiple Announcement API keys enabled, so don’t hesitate to generate a key for each information source. This contributes to both security and manageability.

  • If you want to create a new announcement within a specific announcement category, make sure to create the category in Workspace before you create your API flow. This is because you cannot create new announcement categories from your API flow. By default, new announcements will be added to the 'uncategorized' category.


Configuration

Step 1. Create the Power Automate flow

  1. Log in to Microsoft 365 and click on the waffle button in the top left corner.

  2. Open the app Power Automate.

  3. Choose Create to create a new flow.

  4. Choose Automated cloud flow.

  5. Assign a flow name to your flow. Search for “created or modified properties” as SharePoint trigger to start your flow with and click on Create.

    trigger.png
  6. Select the relevant site from the Site Address dropdown.

  7. Enter the Library Name. If the Site Pages library doesn’t show up in the dropdown field, you need to enter a custom value and use the GUID of the Site Pages library. You can find this value by going to the Site contents and opening the Site Pages settings:

    sites_pages.png



    The GUID is now listed in the URL:

    guid.png
  8. Copy this value from the URL and paste it into the Library Name:

    library_name.png


Step 2. Add a Condition

To filter news posts that are published you can use the metadata field called “Promoted State”. This field has three possible values:

  • 0 = Site Page

  • 1 = News Post in Draft

  • 2 = News Post Published

To add a condition:

  1. Click + New step.

  2. Click Condition twice.

    MicrosoftTeams-image__6_.png
    MicrosoftTeams-image__7_.png
  3. Add the Promoted State field.

    Notice: if you choose an existing library from the drop-down list, the "Promoted State" condition will not be shown. To be able to choose a "Promoted State" condition, you must have filled in a custom GUID under the Library Name.

  4. We only want published news posts, so we set the condition to “is equal to” 2.

    condition_2.png


Step 3. Posting to the Announcements API

  1. In the "If yes" field, add an action and search for HTTP (premium). If you do not have a Power Automate Premium license, you will be offered a 90-day trial license.
    ​​

    action.png

  2. As the Method, choose POST.

  3. The URI is the endpoint URL for the Announcements API of your Workspace 365 environment, e.g:
    https://workspace365instance.url/environmentname/api/announcements.

    method_post.png

  4. Fill in the Authorization header: "Workspace365" followed by the API key for the Announcements API.

    headers.png

  5. An example of the body:

    body.png


    Or in code:

    {
    "Title": "@{triggerOutputs()?['body/Title']}",
    "Description": "@{triggerOutputs()?['body/Description']} <br><br><a href=@{triggerOutputs()?['body/{Link}']}>Read more on Sharepoint</a>"
    }

  6. Save your flow.

  7. Test it by creating a SharePoint news post and post it with the “Post news” button in the top right corner (double-check if you create a post in the same SharePoint site used in the created API flow).
    ​​

    save_and_test.png



    If your flow succeeds you should now see the announcement in Workspace 365!

    In your API flow, you can specify under which category the announcement will be posted. However, the category must already exist in Workspace (you cannot create a new announcement category from your API flow). By default, new announcements will be added to the 'Uncategorized' category.

    announcements_test.png


Background information on the JSON body

The body of the HTTP action is where we provide the announcement, but it needs to be formatted as a JSON object. JSON stands for JavaScript Object Notation and it adheres to a few simple syntax rules:

  • Curly braces hold objects

  • Data is in name/value pairs

  • Data is separated by commas

Whether you use the Workspace 365 Hub to write an announcement or the Announcements API, your announcement will always consist of a few basic elements. The most important ones being a title and content for the users to read. These items are submitted to the API as properties of the JSON object. The only property that is required by the Announcements API is the “Title” property, but an empty announcement is rather useless, so we want to add content as well. The content of the announcement is submitted in the object property called “Description”.

Unfortunately Microsoft doesn’t offer the full content of the news post to be included, but they do offer a shortened version, containing the first 250 characters without styling. The metadata field that contains this data is also called “Description” in SharePoint. Luckily, Workspace 365 accepts HTML code as content for the announcement, so we will complement this data with a clickable link to the full new post on SharePoint. For the URL of the news post, you can use the dynamic content “Link to item”. To make the announcement look a little prettier, add a space and two line break tags between the SharePoint Description and the HTML hyperlink element.


Background information on flow run history

Your Power Automate flow will be triggered by the creation of the post, so the flow will initially report back as Succeeded. However, since the post has only been created but not published, the Promoted State will not equal 2 and the condition we set in our flow will fail. This means the first test will not lead to an announcement. However, since we’ve posted the news once we were done editing, the flow will be triggered a second time shortly after the first time. You will see this in the flow run history.

Click on the blue “Back” arrow in the top left corner of the Power Automate editor window and keep an eye on the runs. It may take a few minutes before the flow is run, but eventually you will see two runs:

runs.png


Optional features

Configure a static Announcements category

If you want announcement to always be made in a specific category, you can define this in the body of the HTTP action. For example setting the Category to the specific value of “Sharepoint”:

{
"Title": "@{triggerOutputs()?['body/Title']}",
"Description": "@{triggerOutputs()?['body/Description']}<br> <br><a href=@{triggerOutputs()?['body/{Link}']}>Read more on Sharepoint</a>",
"Category": {
"Name": "Sharepoint"
}
}


Setting an announcement option through a SharePoint column

If you are able to add columns to the SharePoint Site Pages form, you can use this as an easy way to control announcement options, such as the option to show the announcement as a popup.

Here’s how this works:

The Announcement schema of the Announcements API contains a property called "ShowPopupDirectlyToUser". This option expects a value of “true” or “false”. If you add a column to the Site Pages form with a descriptive name and specify the values expected by the API as possible options, you can pass this information directly to the Announcements API.

create_column.png

This is a column of the type Choice. In this example we have added a description and edited the choices to match the values expected by the API. The default value is false, so we have also set the default value in SharePoint to false. By displaying the choices as a radio button, you enforce a single selection. If you want this option to be mandatory when a news post is made, set “Require that this column contains information” to Yes.

Once this column has been added, we can now add it to our flow as dynamic content. Make sure you choose the Value and not the column title:

value.png


Adding extra conditions to filter news posts

If you want to filter news posts before they are submitted to the Announcements API, you can add extra criteria to the Condition. This can be based on a column value like in the previous example or another metadata field. To add an extra condition criterium, click on the Add button in the Condition and choose “Add row”:

condition2.png

The default operator for the Condition rows is And because you will most likely want to filter based on both criteria. Should you want to filter on either criteria, you can change this to Or. Next, you can specify a criterium in the second row. In this example, we added an extra column to the Site Pages view called “My Filter Column”. Make sure you choose the dynamic content which ends with “Value”, because you want to filter based on the value in the column.

condition3.png

After choosing “My Filter Column Value”, complete the criterium as you see fit:

condition4.png

Did this answer your question?