question

Vijaykanth-9346 avatar image
0 Votes"
Vijaykanth-9346 asked saldana-msft edited

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

Hello there,

found similar issue here : https://docs.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"
}
}
}


office-teams-windows-itpromicrosoft-graph-teamworkmicrosoft-graph-usersmicrosoft-graph-permissions
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Vijaykanth-9346 I first need make sure your outlook account is a work account, please use Graph Explorer to call the https://graph.microsoft.com/v1.0/me endpoint and provide a screenshot.

0 Votes 0 ·

Hey @CarlZhao-MSFT , attached screenshots for

https://graph.microsoft.com/v1.0/m

Response :
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"businessPhones": [],
"displayName": "Vijaykanth",
"givenName": "Vijaykanth",
"jobTitle": null,
"mail": "__vijaykanth.muccharla@infoushur.onmicrosoft.com",
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": null,
"surname": "Muccharla",
"userPrincipalName": "__vijaykanth.muccharla@infoushur.onmicrosoft.com",
"id": "959023ac-869f-483c-881f-1b4bbf3c42ae"
}



201522-graph-profile-me-api.png


0 Votes 0 ·

When I hit POST : send channel message:
https://graph.microsoft.com/v1.0/teams/19%3aA9P-YDSXJECA2nshoOeXP0V3b34phu9JxSR0Sx9IWNQ1%40thread.tacv2/channels/74532001-1f33-45b5-b633-3746165cef32&tenantId=39d3b23a-317d-473a-ab1d-5ce6b45ba26b/messages


Response :
{
"error": {
"code": "Forbidden",
"message": "Missing scope permissions on the request. API requires one of 'ChannelMessage.Send, Group.ReadWrite.All'. Scopes on the request 'openid, profile, User.Read, email'",
"innerError": {
"date": "2022-05-12T12:52:27",
"request-id": "2e874948-3185-4ad9-a8e9-774def379a2c",
"client-request-id": "a87f48bc-e7b7-9203-f1d3-f8fa5263591b"
}
}
}

0 Votes 0 ·

@Vijaykanth-9346 Your token is missing permissions, can you ask your admin to grant you Group.ReadWrite.All or ChannelMessage.Send permissions?

0 Votes 0 ·
Show more comments

1 Answer

CarlZhao-MSFT avatar image
0 Votes"
CarlZhao-MSFT answered Vijaykanth-9346 commented

Hi @Vijaykanth-9346

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.



2022-05-17-175228.png (119.8 KiB)
image.png (8.6 KiB)
image.png (90.1 KiB)
image.png (60.6 KiB)
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Vijaykanth-9346 Would you please provide us with an update on the status of your issue?

0 Votes 0 ·

@CarlZhao-MSFT Thank you for the steps provided.. Let me try these instructions and confirm asap.

1 Vote 1 ·

@CarlZhao-MSFT Our admin has logged in and could not find Teams Application under App Registrations. Attached SS. What could be the reason?

203081-image.png


0 Votes 0 ·
image.png (55.8 KiB)

@Vijaykanth-9346 Is Teams Application registered in your Azure Ad?

0 Votes 0 ·
Show more comments