Precondition Failed error 412 when trying to post a message to chat using Microsoft Graph REST API

Prakash 5 Reputation points
2023-07-04T06:01:54.6366667+00:00

Hi, we are using below Microsoft Graph API to send a message to the team's chat. But we are getting below error message.

POST End Point: https://graph.microsoft.com/beta/users/{user-id}/chats/{chat-id}/messages

{
    "error": {
        "code": "PreconditionFailed",
        "message": "Requested API is not supported in application-only context",
        "innerError": {
            "date": "<date>",
            "request-id": "<request-id>",
            "client-request-id": "<client-request-id>"
        }
    }
}

We also given all permissions for the application from the Azure end, by referring this thread https://learn.microsoft.com/en-us/answers/questions/506591/precondition-failed-error-412-when-trying-to-creat?comment=answer-507413&page=1#comment-1318025. Please help to resolve this issue. Thanks in advance.

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

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,366 Reputation points
    2023-07-04T07:10:23.4166667+00:00

    Hi @Prakash

    As your error message indicates, sending messages in chat does not support application-only contexts. So you must grant delegated permissions to your app and use the delegated authentication flow (auth code flow or ROPC flow) to obtain an access token.

    User's image

    Hope this helps.

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


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.