Why is error: 400 occuring? 400 {'error': {'code': 'BadRequest', 'message': "'user@odata.bind' field is missing in the request.", 'innerError': ...

Michael Wilcox 26 Reputation points
2024-11-13T22:26:20.9633333+00:00
    Here is a snippet of my code. Why is error 400 occuring:  ie  400  {'error': {'code': 'BadRequest', 'message': "'user@odata.bind' field is missing in the request.", 'innerError': {'date': '2024-11-13T22:20:30', 'request-id': '5675829f-5a', 'client-request-id': '567582a'}}} ? 

	# Create a new chat
    chat_payload = {
        "chatType": "oneOnOne",
        "members": [
            {
                "@odata.type": "#microsoft.graph.aadUserConversationMember",
                "roles": ["owner"],
                "user@odata.bind": "https://graph.microsoft.com/v1.0/me"
            },
            {
                "@odata.type": "#microsoft.graph.aadUserConversationMember",
                "roles": ["owner"],
                "user@odata.bind": f"https://graph.microsoft.com/v1.0/users{user_email}"
            }
        ]
    }
    # print("headers", headers, "chat payload",chat_payload)
    response = requests.post('https://graph.microsoft.com/v1.0/chats', headers=headers, json=chat_payload )
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,800 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rajat Vashistha-MSFT 180 Reputation points Microsoft Vendor
    2024-12-31T10:18:57.1033333+00:00

    Hi Michael Wilcox,

    Thank you for contacting Microsoft!

    The error 400 with the message "'user@odata.bind' field is missing in the request" typically occurs due to an issue with the format or content of the request being sent.

    It seems you might be trying to use {user_email} in the "user@odata.bind" field. Instead, please use the "Id" which can be fetched via the following endpoint: https://graph.microsoft.com/v1.0/users.

    POST https://graph.microsoft.com/v1.0/chats
    Content-Type: application/json
    
    {
      "chatType": "oneOnOne",
      "members": [
        {
          "@odata.type": "#microsoft.graph.aadUserConversationMember",
          "roles": ["owner"],
          "user@odata.bind": "https://graph.microsoft.com/v1.0/users('8b0xxxxx-4792-4def-b2c9-c363a1xxxxxx')"
        },
        {
          "@odata.type": "#microsoft.graph.aadUserConversationMember",
          "roles": ["owner"],
          "user@odata.bind": "https://graph.microsoft.com/v1.0/users('82axxxxx-f7cc-4a2e-a728-3a5df2xxxxxx')"
        }
      ]
    }
    

    For more details on creating a one-on-one chat, please refer to the documentation here:

    https://zcusa.951200.xyz/en-us/graph/api/chat-post?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.