question

NageshJoshi-7871 avatar image
0 Votes"
NageshJoshi-7871 asked NageshJoshi-7871 answered

Create a Security Group using Graph API with Service Principal as an Owner

I was trying to create a security group as mentioned in the below link - example 2
https://docs.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=http

I am able to create a security group with the {user} as an owner to the newly created group. However, when I am trying to create a new group with the service principal as an owner it is failing. Is there a way with which I can create a security group with the service principal as an owner to it in a single API?

I have tried with the following approach as well:
"owners@odata.bind": [
"https://graph.microsoft.com/v1.0/servicePrincipals/00964c82-a7c2-4675-bbed-54bcf16328b3"
]

microsoft-graph-groups
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CarlZhao-MSFT avatar image
0 Votes"
CarlZhao-MSFT answered CarlZhao-MSFT edited

Of course can create group in a single request and set the service principal as the owner of the group, and I think the method you tried in the question is correct, my test results:

131394-image.png

131442-image.png


You can try to call the api in Graph Explorer and tell me the result.



If an Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (76.7 KiB)
image.png (40.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NageshJoshi-7871 avatar image
0 Votes"
NageshJoshi-7871 answered CarlZhao-MSFT commented

Thank you for your prompt response.
I am getting the following error:
{
"error": {
"code": "Request_ResourceNotFound",
"message": "{Resource 'Object ID of SPN}' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"request-id": "bcb7957e-c847-4934-a33e-de981cc94e14",
"date": "2021-09-13T02:59:00",
"client-request-id":"d5827179-30ad-c7d5-7718-2f8a0e503432"
}
}
}

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is caused by your service principal id error. Please make sure that the service principal id you use is correct.

0 Votes 0 ·

You can use GET https://graph.microsoft.com/v1.0/servicePrincipals to list your service principal id, and then use the correct id you get to create group. I think it should be successful.

0 Votes 0 ·
NageshJoshi-7871 avatar image
0 Votes"
NageshJoshi-7871 answered

Thanks a lot @CarlZhao-MSFT.
It is working properly now.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.