Forum Discussion

mohamadmomo's avatar
mohamadmomo
Copper Contributor
Nov 27, 2024
Solved

adding an AAD security group to site collection administrator using power automate

so im trying to do what the title says but i keep getting the error from the flow that the group cannot be found although it exists and i can find it connected to the sharepoint site here is the http request i have been trying :
{ "inputs": { "host": { "connectionName": "shared_sharepointonline", "operationId": "HttpRequest", "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline" }, "parameters": { "dataset": "https://xxxtest.sharepoint.com/teams/@{body('Parse_JSON')?['groupAlias']}", "parameters/method": "POST", "parameters/uri": "_api/web/sitegroups/getbyname('Site Collection Administrators')/users", "parameters/headers": { "Accept": "application/json;odata=verbose", "Content-Type": "application/json" }, "parameters/body": "{\n \"LoginName\": \"i:0#.f|membership|THE_GROUP_NAME\"\n}\n" }, "authentication": "@parameters('$authentication')" }, "metadata": { "operationMetadataId": "new-operation-id" } }

I presume im writing something wrong in the api request or in the body but i couldnt find any helpful resources that does exactly what im doing , the closest thing i found is this (adding a role permission which worked when i tried it and it could find the group , but i want it to add the group to the site collection admins not just give it a permission):
https://ganeshsanapblogs.wordpress.com/2022/11/05/sharepoint-online-grant-permissions-to-azure-ad-security-group-using-power-automate-and-rest-api/

  • hi , thank you for your answer, yes this format worked at the end but you can add them in one HTTP request no need for 2:

    {

      "type": "OpenApiConnection",

      "inputs": {

        "parameters": {

          "dataset": "https://.sharepoint.com/",

          "parameters/method": "POST",

          "parameters/uri": "_api/web/siteusers",

          "parameters/headers": {

            "content-type": "application/json;odata=nometadata",

            "accept": "application/json;odata=nometadata"

          },

          "parameters/body": "{\n    \"LoginName\": \"c:0t.c|tenant|a1e0c1af-...\",\n    \"IsSiteAdmin\": true\n}"

        },

        "host": {

          "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline",

          "connection": "shared_sharepointonline",

          "operationId": "HttpRequest"

        }

      },

      "runAfter": {

        "Compose": [

          "Succeeded"

        ]

      }

    }

2 Replies

  • mohamadmomo's avatar
    mohamadmomo
    Copper Contributor

    hi , thank you for your answer, yes this format worked at the end but you can add them in one HTTP request no need for 2:

    {

      "type": "OpenApiConnection",

      "inputs": {

        "parameters": {

          "dataset": "https://.sharepoint.com/",

          "parameters/method": "POST",

          "parameters/uri": "_api/web/siteusers",

          "parameters/headers": {

            "content-type": "application/json;odata=nometadata",

            "accept": "application/json;odata=nometadata"

          },

          "parameters/body": "{\n    \"LoginName\": \"c:0t.c|tenant|a1e0c1af-...\",\n    \"IsSiteAdmin\": true\n}"

        },

        "host": {

          "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline",

          "connection": "shared_sharepointonline",

          "operationId": "HttpRequest"

        }

      },

      "runAfter": {

        "Compose": [

          "Succeeded"

        ]

      }

    }

  • michalkornet's avatar
    michalkornet
    Iron Contributor

    Hi mohamadmomo  , Hi, please try this method to set an Entra (AAD) group as the site collection admin. Logon Name should have  c:0t.c|tenant|GROUPID prefix

     

Resources