Error: "The navigation bind for the user was missing in request" when creating a team using Microsoft Graph API
Body:
I am encountering an error while trying to create a team using the Microsoft Graph API in my Azure Function. The error message I receive is as follows:
System.Private.CoreLib: Exception while executing function: Functions.create_azure_ad_group.
System.Private.CoreLib: Result: Failure
Exception: ODataError:
APIError
Code: 400
message: None
error: MainError(additional_data={}, code='BadRequest', details=None, inner_error=InnerError(additional_data={}, client_request_id='0ae9a494-a931-4974-aa17-e96e0f05e11a', date=DateTime(2024, 10, 17, 15, 6, 28, tzinfo=Timezone('UTC')), odata_type=None, request_id='74021609-1bad-43fd-b8e9-034fd1c65fbb'), message='The navigation bind for the user was missing in request', target=None)
Here is the relevant code I am using to create a team:
owner_member = AadUserConversationMember(
roles=[
"owner",
],
id=f"https://graph.microsoft.com/v1.0/users('3e3af652-daba-4d47-bfba-968bcc92da04')",
additional_data={
"user@odata_bind": "https://graph.microsoft.com/v1.0/users('3e3af652-daba-4d47-bfba-968bcc92da04')",
}
)
request_body = Team(
display_name=group_name,
description="Communication platform of " + group_name,
additional_data={
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
},
members=[owner_member]
)
result = await graph_client.teams.post(request_body)
I would appreciate any guidance on how to resolve this error. It seems to indicate that there is an issue with the way I am binding the user in the request.
Thank you in advance for your help!
What I Tried: I have verified that the user ID I am using in the owner_member object is correct and exists in Azure Active Directory. I also ensured that the user@odata_bind property is correctly formatted to point to the same user. I attempted to create the team multiple times with the same approach, but the error persists. Additionally, I reviewed the Microsoft Graph API documentation for creating teams and binding users but did not find a clear indication of what might be wrong.
What I Expected: I expected the request to successfully create a team with the specified owner member without any errors. I anticipated that the team would be created with the provided display name, description, and the owner role assigned to the specified user.
Initially, I registered one application and granted Team.Create
permission of Application type by granting admin consent like this:
To create team using Microsoft Graph API, you can make use of below sample python code:
import asyncio
from azure.identity import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.team import Team
from msgraph.generated.models.aad_user_conversation_member import AadUserConversationMember
CLIENT_ID = 'appId'
CLIENT_SECRET = 'secret'
TENANT_ID = 'tenantId'
SCOPES = ['https://graph.microsoft.com/.default']
credential = ClientSecretCredential(
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET
)
graph_client = GraphServiceClient(credential)
async def create_team(group_name):
owner_member = AadUserConversationMember(
roles=["owner"],
id="https://graph.microsoft.com/v1.0/users('userId')",
additional_data={
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('userId')",
}
)
request_body = Team(
display_name=group_name,
description=f"Communication platform of {group_name}",
additional_data={
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
},
members=[owner_member]
)
result = await graph_client.teams.post(request_body)
print("Team created successfully")
asyncio.run(create_team("Demoteam2110"))
Response:
To confirm that, I checked the same in Portal where Microsoft 365 group created with same properties successfully like this: