How can we combine the powers of two fantastic automation tools, Microsoft Graph API and Microsoft Flow?

As an example we will create a team in Microsoft Teams with the help of a simple form in Microsoft Forms, Microsoft Flow and Microsoft Graph API.

We start by registering an application in Azure AD
Go to Azure AD -> App registrations -> New registration
We choose a name and click “Register”
Make a note of the client ID and the tenant ID
Go to “Certificates & secrets”, click “New client secret”
Give a name to the secret and choose when it should expire. Clock “Add” and make a note of the secret when it has been created
Go to “API permissions” and click “Add a permission”
Choose “Microsoft Graph”
Add the permissions you need. In this example we add Group.ReadWrite.All, User.ReadWrite.All and Directory.ReadWrite.All
Click “Grant admin consent for Contoso” since we plan to use Graph API with application authentication
Create a simple form in Microsoft Forms that asks the user for a wanted name of the new team
Create a new flow in Microsoft Flow. Make it trigger on a new response from Forms and choose the form you have created
Create variables for the Tenant ID, Client ID and App Secret and add the values from the application we registered earlier
We also create variables for the name of our new group and the group owner. Give them temporary values
We insert the action to get Forms responses and set our group name and owner variables to the input of the form and the responders email address
Next we get the group owners Office 365 user profile

At this point we could add an approval before we continue, but let us skip that for now.

Time for our first call to Graph API. From the Graph API documentation we get the Method and URI to call. We add Content-Type application/json to the header and insert the needed JSON in the body. We use the owners department in the group name.
Click “Show advanced options” and add the Tenant ID, Client ID, Secret and enter https://graph.microsoft.com as the audience
Add the action “Parse JSON” to get the response from the Grap API call we used to create a group.

For this response the schema is:

{
    "type": "object",
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "id": {
            "type": "string"
        },
        "deletedDateTime": {},
        "classification": {},
        "createdDateTime": {
            "type": "string"
        },
        "creationOptions": {
            "type": "array"
        },
        "description": {
            "type": "string"
        },
        "displayName": {
            "type": "string"
        },
        "groupTypes": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "mail": {
            "type": "string"
        },
        "mailEnabled": {
            "type": "boolean"
        },
        "mailNickname": {
            "type": "string"
        },
        "onPremisesLastSyncDateTime": {},
        "onPremisesSecurityIdentifier": {},
        "onPremisesSyncEnabled": {},
        "preferredDataLocation": {},
        "proxyAddresses": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "renewedDateTime": {
            "type": "string"
        },
        "resourceBehaviorOptions": {
            "type": "array"
        },
        "resourceProvisioningOptions": {
            "type": "array"
        },
        "securityEnabled": {
            "type": "boolean"
        },
        "visibility": {
            "type": "string"
        },
        "onPremisesProvisioningErrors": {
            "type": "array"
        }
    }
}

We add another HTTP action to add the sender of the form as the owner of the new group. We use the id from the Parse JSON in the URI and the ID of the O365 User Profile in the body.
Click “Show advanced options” and add the same values as the last call (Tenant ID, Client ID, Secret and Audience).
We add our last HTTP call to create the team. We use the id from the Parse JSON in the header and the same values as before under Advanced settings.
We test the flow, enter our wanted team name in the form and hit Submit.
Congratulations, you have just created a team in Microsoft Teams throug Microsoft Flow and Graph API.