Precondition Failed error 412 when trying to create chats for a users to have one to one chat using Microsoft Graph REST API

Nikita Pandey 146 Reputation points
2021-08-09T12:29:54.963+00:00

I am getting the following error while trying "https://graph.microsoft.com/v1.0/chats" this Microsoft Graph API.

'{

"error": {  

    "code": "PreconditionFailed",  

    "message": "Requested API is not supported in application-only context",  

    "innerError": {  

        "date": "2021-06-29T07:17:55",  

        "request-id": "1d580324-d584-453e-93b9-352c41c23ae0",  

        "client-request-id": "1d580324-d584-453e-93b9-352c41c23ae0"  

    }  

}  

}'

As I have added the JSON in body of request as below:-

{
"chatType": "oneOnOne",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": "",
"@odata.bind": "https://graph.microsoft.com/v1.0/users/3218324a-82a0-44b5-b0cb-34adbbc51fc7"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": "owner",
"
@odata.bind": "https://graph.microsoft.com/v1.0/users/54b11e04-5612-4716-8777-a540977b636e"
}
]
}

![121612-image.png]1

Please help me on this, I need to validate Create chat API in Postman.

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,366 Reputation points
    2021-08-10T02:31:50.393+00:00

    As your error message says, creating chat does not support application-only context for the time being, it currently only supports user context.

    121763-image.png

    So you need to grant Chat.Create delegation permission for your application, and then you need to use the auth code flow with user participation to get the access token, and then you will be able to use the user token to call the /chats api endpoint to create chats for the user .


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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.