user1063287
user1063287

Reputation: 10879

How to create Microsoft Team via Microsoft Graph API with Owners specified by User Email rather than User ID?

Desired Behaviour

Create a Microsoft Team, with specified Owners and Members, in a Power Automate Flow using the HTTP connector to make requests to the Microsoft Graph API.

Actual Behaviour

This code shows how you can create a Microsoft Team whilst specifying it's Owners by User ID.

{
    "[email protected]": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    "displayName": "My Sample Team",
    "description": "My Sample Team’s Description",
    "members": [
    {
        "@odata.type": "#microsoft.graph.aadUserConversationMember",
        "roles": [
            "owner"
        ],
        "[email protected]": "https://graph.microsoft.com/v1.0/users('0040b377-61d8-43db-94f5-81374122dc7e')"
    }]
}

Source

For reference, the Graph API docs entry for Get a user (which is used to specify the Owner in the code above), specifies the endpoint syntax as:

GET /users/{id | userPrincipalName}  

Currently, I do not have access to users' id or userPrincipalName.

What I've Tried

I am using a Power Automate Flow with the SharePoint For a selected item trigger.

The list includes two columns of type Person where Owners and Members are specified.

In order to get a list of Owners, I am using the SharePoint connector's Get item action on the selected item and then using an Apply to each control to iterate over each columns' values.

Below is the Raw Output of Get Item - the Owners column array is TeamOwner_x002f_s.

You can see that each object only has DisplayName and Email and not User ID or userPrincipalName:

{
    "statusCode": 200,
    "headers": {
        "Transfer-Encoding": "chunked",
        "Vary": "Origin,Accept-Encoding",
        "X-SharePointHealthScore": "1",
        "X-MS-SPConnector": "1",
        "X-SP-SERVERSTATE": "ReadOnly=0",
        "DATASERVICEVERSION": "3.0",
        "SPClientServiceRequestDuration": "68",
        "SPRequestGuid": "letters-and-numbers",
        "request-id": "letters-and-numbers",
        "MS-CV": "letters-and-numbers.0",
        "Strict-Transport-Security": "max-age=31536000",
        "X-FRAME-OPTIONS": "SAMEORIGIN",
        "Content-Security-Policy": "frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.office.com *.stream.azure-test.net *.microsoftstream.com;",
        "MicrosoftSharePointTeamServices": "numbers-and-dots",
        "X-Content-Type-Options": "nosniff",
        "X-MS-InvokeApp": "1; RequireReadOnly",
        "Timing-Allow-Origin": "*",
        "x-ms-apihub-cached-response": "false",
        "Cache-Control": "max-age=0, private",
        "Date": "Sun, 04 Jul 2021 06:42:53 GMT",
        "P3P": "CP=\"SOME CODES HERE\"",
        "X-AspNet-Version": "4.0.30319",
        "X-Powered-By": "ASP.NET",
        "Content-Type": "application/json; charset=utf-8",
        "Expires": "Sat, 19 Jun 2021 06:42:54 GMT",
        "Last-Modified": "Sun, 04 Jul 2021 06:42:54 GMT",
        "Content-Length": "3938"
    },
    "body": {
        "@odata.etag": "\"2\"",
        "ItemInternalId": "1",
        "ID": 1,
        "Title": "View",
        "Year": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            "Id": 2,
            "Value": "2023"
        },
        "Year#Id": 2,
        "ProgramType": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            "Id": 0,
            "Value": "Program Type 01"
        },
        "ProgramType#Id": 0,
        "ProgramName": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            "Id": 1,
            "Value": "02"
        },
        "ProgramName#Id": 1,
        "TeamOwner_x002f_s": [
            {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "i:0#.f|membership|[email protected]",
                "DisplayName": "User Name 1",
                "Email": "[email protected]",
                "Picture": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/UserPhoto.aspx?Size=L&[email protected]",
                "Department": null,
                "JobTitle": null
            },
            {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "i:0#.f|membership|[email protected]",
                "DisplayName": "User Name 2",
                "Email": "[email protected]",
                "Picture": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/UserPhoto.aspx?Size=L&[email protected]",
                "Department": null,
                "JobTitle": null
            }
        ],
        "[email protected]": "#Collection(Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser)",
        "TeamOwner_x002f_s#Claims": [
            "i:0#.f|membership|[email protected]",
            "i:0#.f|membership|[email protected]"
        ],
        "TeamOwner_x002f_s#[email protected]": "#Collection(String)",
        "Team_x0020_Member_x002f_s": [
            {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "i:0#.f|membership|[email protected]",
                "DisplayName": "User Name 3",
                "Email": "[email protected]",
                "Picture": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/UserPhoto.aspx?Size=L&[email protected]",
                "Department": null,
                "JobTitle": null
            }
        ],
        "[email protected]": "#Collection(Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser)",
        "Team_x0020_Member_x002f_s#Claims": [
            "i:0#.f|membership|[email protected]"
        ],
        "Team_x0020_Member_x002f_s#[email protected]": "#Collection(String)",
        "Status": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            "Id": 0,
            "Value": "Details Added"
        },
        "Status#Id": 0,
        "Modified": "2021-07-04T03:57:16Z",
        "Created": "2021-07-04T03:51:18Z",
        "Author": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            "Claims": "i:0#.f|membership|[email protected]",
            "DisplayName": "User Name 1",
            "Email": "[email protected]",
            "Picture": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/UserPhoto.aspx?Size=L&[email protected]",
            "Department": null,
            "JobTitle": null
        },
        "Author#Claims": "i:0#.f|membership|[email protected]",
        "Editor": {
            "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            "Claims": "i:0#.f|membership|[email protected]",
            "DisplayName": "User Name 1",
            "Email": "[email protected]",
            "Picture": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/UserPhoto.aspx?Size=L&[email protected]",
            "Department": null,
            "JobTitle": null
        },
        "Editor#Claims": "i:0#.f|membership|[email protected]",
        "{Identifier}": "Lists%252fMy%2bList%2bName%252f1_.000",
        "{IsFolder}": false,
        "{Thumbnail}": {
            "Large": null,
            "Medium": null,
            "Small": null
        },
        "{Link}": "https://my-tenant.sharepoint.com/sites/ExampleTeam/_layouts/15/listform.aspx?PageType=4&ListId=list-id-here&ID=1&ContentTypeID=content-type-id-here",
        "{Name}": "View",
        "{FilenameWithExtension}": "View",
        "{Path}": "Lists/My List Name/",
        "{FullPath}": "Lists/My List Name/1_.000",
        "{VersionNumber}": "2.0"
    }
}

Question

Is it possible to specify Team members by Email in the Graph API request? Or do I need to somehow get the User ID of each user specified (and if so, what is the best way to do that)?

Update

I tried this HTTP connector GET request in the hopes it would return User ID for each Person:

https://graph.microsoft.com/v1.0/sites/site-id-here/lists/list-id-here/items/item-id-here?expand=fields(select=TeamOwner%5Fx002f%5Fs)

But it returned even less information:

"fields": {
    "@odata.etag": "\"letters-and-numbers,2\"",
    "TeamOwner_x002f_s": [{
            "LookupId": 9,
            "LookupValue": "User Name 1",
            "Email": "[email protected]"
        },
        {
            "LookupId": 27,
            "LookupValue": "User Name 2",
            "Email": "[email protected]"
        }
    ]
}

API docs reference for this approach

Get specific column values of a listItem

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}?expand=fields(select=Column1,Column2)

Upvotes: 1

Views: 793

Answers (1)

Hunaid Hanfee-MSFT
Hunaid Hanfee-MSFT

Reputation: 926

You can get the user information from Microsoft Graph itself, what you can try out is List Users with filter parameter.

like this: GET https://graph.microsoft.com/v1.0/users?$filter(mail eq '[email protected]')

OR

You can list all users and do a mail/displayName search(Ctrl+F) on results at graph explorer.

By these you will be able to get userPrincipalName as well as id.

Permission required:- One of the following permissions is required to call this API.

  • Delegated (work or school account) - User.ReadBasic.All, User.Read.All, User.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, Directory.AccessAsUser.All

  • Delegated (personal Microsoft account) - Not supported.

  • Application - User.Read.All, User.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All

Thanks.

Upvotes: 1

Related Questions