Send messages in Channel APIs we have added the Application permission even if added application permission we are unable send message in channel we are getting 401 Unauthorized response

Abdul Shuaib 36 Reputation points
2023-01-06T13:51:25.137+00:00

Application permission added these for this below api call:- Application permission (Teamwork.Migrate.All ,Chat.Send) is not availabe in our application permission account

send messages url:- https://graph.microsoft.com/v1.0/teams/{{team_id}}/channels/{{channel_id}}/messages
headers = {
'Authorization': 'Bearer Token',
'Content-Type': 'application/json'
}
Body request:{
"body":{
"content":"Hello World"
}
}

After providing above all information after sending request to APIs we are getting 401 Unauthorized
{
"error": {
"code": "Unauthorized",
"message": "Message POST is allowed in application-only context only for import purposes. Refer to https://learn.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.",
"innerError": {
"date": "2023-01-04T11:36:41",
"request-id": "65ea2672-0e88-4b69-af87-67b6cc172770",
"client-request-id": "65ea2672-0e88-4b69-af87-67b6cc172770"
}
}
}

Microsoft Security | Microsoft Graph
0 comments No comments
{count} vote

Accepted answer
  1. Shivam Dhiman 6,081 Reputation points
    2023-01-09T02:06:08.337+00:00

    Hi @Abdul Shuaib

    You are getting this error because of Application permissions. As per the documentation, Application permissions are only supported for migration.
    Otherwise, this API does not support Application permissions.

    In case: your team is not in migration you need to use delegated permissions and I have tried this Graph API using delegated permissions, its working as expected. Please refer to the below sample screenshot
    277170-channel.png

    Hope this helps.

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


2 additional answers

Sort by: Most helpful
  1. CarlZhao-MSFT 46,376 Reputation points
    2023-01-09T02:16:18.09+00:00

    Hi @Abdul Shuaib

    As the documentation says, application permissions are only supported for migration. This means that your team and channel must both be created in a migrated state, otherwise you can only send chat messages in a delegated context.

    277301-26.png

    Call this api endpoint in graph explorer:

    277276-27.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.


  2. Abdul Shuaib 36 Reputation points
    2023-01-16T07:58:39.28+00:00

    Hi @CarlZhao-MSFT
    for send messages in channel endpoint as you suggested above comment auth code flow one I was tried that mechanism was not supported our platform and our higher authority disagree this flow
    second one I have tried ROPC flow here I am getting error while access access token you could refer below snipshot image
    auth_body_param

    above params I was passed as per documentation.
    after sending request I was got these below respone

    ROPC_auth_response

    grant type

    could please help us resloving these authentication issue, and if you are availabe could we have meeting abot this issue it would be better. if agree with meeting send me the your avaiblity date and time

    thank you


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.