blog.atwork.at

news and know-how about microsoft, technology, cloud and more.

Create a new Viva Engage Community with Graph

In early 2023, Microsoft renamed Yammer to Viva Engage. This year we see the first small integration of Viva Engage with Microsoft Graph in beta. This article shows how to provision a new Viva Engage community, add owners and members using Graph in an Azure Logic app.

The goal is to automatically create a new Viva Engage Community which means technically, to create a Microsoft 365 group that is enabled as - sorry, I'm still using the old name - Yammer Community. Currently, Microsoft Graph beta provides a preview feature. See the details at Use the Microsoft Graph API to work with Viva Engage (preview). When using this method, remember that APIs under the /beta version in Microsoft Graph are subject to change.

image

I tested the provisioning and adding owners and members with the beta API as described at Create community. Basically it works as expected, although there are currently a few small problems that I had to work around as follows.

So, here´s the step-by-step guide to create the new community, add owners, and add members.

  • Create an application in Microsoft Entra with the Graph API permission for authentication.
  • Create a new Azure Logic App (or use PowerShell or any other programing language).
  • Execute a HTTP POST against https://graph.microsoft.com/beta/employeeExperience/communities. with the app credentials in the header. The body contains the payload. Here, we create a new community with the name "Finance 10":
  • {
    "description": "A community where financial advisors who represent customers from software engineering profession can discuss advice and suggestions for their clients.",
    "displayName": "Finance 10",
    "owners@odata.bind": [
    "https://graph.microsoft.com/beta/users/<owner1-userid>",
    "https://graph.microsoft.com/beta/users/<owner2-userid>"
    ],
    "privacy": "private"
    }
  • As we can see, we can add up to two owners for the community. Note that this method requires the userid, and not the UPN. So, we have to lookup the userid first to be able to use it here.
  • The result should be a HTTP status code 200. The body contains some properties, and the resourceId. This is the newly generated communityid (we call it this to distinguish the long community ID and the Entra group ID). We need to use this communityid for getting this group as follows.
  • Then, we do another HTTP GET request against https://graph.microsoft.com/beta/employeeExperience/communities/<communityid>. to get the groupid.
  • The result should be a HTTP status code 200. The body contains some properties, and the groupid. We need the groupid to add members to the community.
  • We need a delay until the new group is available in the Graph groups. In my tests, I used 1 minute, otherwise the group lookup did not work.
  • We can now add members with a HTTP POST https://graph.microsoft.com/beta/groups/<groupid>/members/$ref and the userid we want to add (as above):
    {
    "@odata.id": https://graph.microsoft.com/beta/directoryObjects/<member-userid>
    }
  • The result should be a HTTP status code 204 (with no body)

The workaround of fetching the new group for getting the groupid and waiting for the new group to be available in Graph is currently required. However, this may no longer be necessary when this functionality is available in the v1 endpoint. This is the complete and working flow.

image

Create Community works as follows:

image

We use a Parse JSON action and a variable to easily work with the HTTP result in the following actions.

image

The action getgroup does the lookup of the newly created group. Again, we use Parse JSON to get the groupid and set it to a variable.

image

At the end, we add one member. Since the key value of the member body contains "@odata.id", I workarounded that with a concat('@','odata.id') function to avoid errors when saving the Logic App.

image

You can find the complete Azure Logic App for download in my GitHub repo AzureAndGraph here.

As result, this flow creates the new Viva Engage Community with the two owners, and one member.

image

I hope this article helps you use the preview version of Graph for Viva Engage sucessfully!

Loading