Unable to send Chat message to a channel or chat with Graph API, thrwos an error.

Vijaykanth 6 Reputation points
2022-05-12T09:11:17.71+00:00

Hello there,

found similar issue here : https://learn.microsoft.com/en-us/answers/questions/568047/graph-rest-api-to-send-a-message-to-a-teams-channe.html
As @CarlZhao-MSFT suggested I used a Work/School account. But issue still persists. I have asked my Admin to Enable Permissions. But they could not enable it.

I have logged in with Work Account but still getting the same response. Could you please provide steps to enable these permissions? Or any other help I would be appreciate201366-graph-api-error.png201327-app-permissions-ushur-ms-account.png. Thanks much!

PS. Note : I am trying to use these APIs via Tray.io Integration Tool attached Screenshots 201375-new-ms-work-accnt-authpermissions.pngplease refer.

{
"error": {
"code": "InternalServerError",
"message": "Unable to find target address",
"innerError": {
"date": "2022-05-11T09:00:47",
"request-id": "e735d22d-e788-469d-afbc-954f6f60e840",
"client-request-id": "e86da880-ff14-de48-f2e6-15c94fa02a60"
}
}
}

Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,376 Reputation points
    2022-05-17T10:19:34.62+00:00

    Hi @Vijaykanth

    First grant your application the ChannelMessage.Send delegated permission.

    Go to the Azure AD portal and log in with the global administrator>App registrations>your app>API permissions>Add a permission.

    202742-2022-05-17-175228.png

    Then use the auth code flow to get the access token:

    1.Run the URL in the browser and log in with your work account to get the authorization code.

    https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?  
    client_id={client id}  
    &response_type=code  
    &redirect_uri={redirect url}  
    &response_mode=query  
    &scope=ChannelMessage.Send  
    &state=12345  
    

    202761-image.png

    2.Redeem an access token with your authorization code in postman.

    202724-image.png

    Finally use the token to call the graph api endpoint to send the message.

    202735-image.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.


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.