Send chatMessage in channel endpoint returns 401 Unauthorized even though the token is valid

Kuo Ian 1 Reputation point
2022-06-21T02:00:51.9+00:00

The Send chatMessage in channel endpoint returns 401 Unauthorized even though the token is valid.
In addition, list chats has the same issue.

Send chatMessage in channel API ref: https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
List Chats API ref: https://learn.microsoft.com/en-us/graph/api/chat-list?view=graph-rest-1.0&tabs=http

We already confirmed required permissions are given.

Failed request (Send chatMessage in channel):

Graph Explorer:
https://developer.microsoft.com/en-us/graph/graph-explorer?request=teams%2F321f6a10-19f2-4e89-a8a4-67b07bd8f189%2Fchannels%2F19%3A579884d012a34058b3ab9224a8d5051a%40thread.skype%2Fmessages&method=POST&version=v1.0&GraphUrl=https://graph.microsoft.com
213181-screen-shot-2022-06-21-at-110518.png

Curl:

> curl -v -k --request POST 'https://graph.microsoft.com/v1.0/teams/321f6a10-19f2-4e89-a8a4-67b07bd8f189/channels/19:579884d012a34058b3ab9224a8d5051a@thread.skype/messages'
> --header 'Authorization: token_ommited_as_it_is_still_valid_now'
> --header 'Content-Type: application/json'
> --data-raw '{"body":{"contentType":"html","content":"<div><div>jdnd</div></div>"},"mentions":[],"attachments":[]}'

Response:

  • Mark bundle as not supporting multiuse
    < HTTP/1.1 401 Unauthorized
    < Transfer-Encoding: chunked
    < Content-Type: application/json
    < Strict-Transport-Security: max-age=31536000
    < request-id: 725acdca-123a-47a5-92dc-247aeeb426cf
    < client-request-id: 725acdca-123a-47a5-92dc-247aeeb426cf
    < x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"Japan West","Slice":"E","Ring":"2","ScaleUnit":"002","RoleInstance":"OS1PEPF00005643"}}
    < Date: Tue, 21 Jun 2022 01:55:28 GMT
    <
  • Connection #0 to host graph.microsoft.com left intact
    {"error":{"code":"Unauthorized","message":"UnknownError","innerError":{"date":"2022-06-21T01:55:28","request-id":"725acdca-123a-47a5-92dc-247aeeb426cf","client-request-id":"725acdca-123a-47a5-92dc-247aeeb426cf"}}}

A counterexample using same token: Request to /me endpoints

Request:

Graph Explorer:
https://developer.microsoft.com/en-us/graph/graph-explorer?request=me&method=GET&version=v1.0&GraphUrl=https://graph.microsoft.com&requestBody=eyJib2R5Ijp7ImNvbnRlbnRUeXBlIjoiaHRtbCIsImNvbnRlbnQiOiI8ZGl2PjxkaXY+amRuZDwvZGl2PjwvZGl2PiJ9LCJtZW50aW9ucyI6W10sImF0dGFjaG1lbnRzIjpbXX0=
213128-screen-shot-2022-06-21-at-110501.png

Curl:
curl -v -k 'https://graph.microsoft.com/v1.0/me'
--header 'Authorization: Bearer token_ommited_as_it_is_still_valid_now’

Response:

  • Mark bundle as not supporting multiuse
    < HTTP/1.1 200 OK
    < Cache-Control: no-cache
    < Transfer-Encoding: chunked
    < Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
    < Strict-Transport-Security: max-age=31536000
    < request-id: 3829ad44-6806-40cb-9854-a60e4544e25c
    < client-request-id: 3829ad44-6806-40cb-9854-a60e4544e25c
    < x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"Japan West","Slice":"E","Ring":"2","ScaleUnit":"001","RoleInstance":"OS1PEPF0000566D"}}
    < x-ms-resource-unit: 1
    < OData-Version: 4.0
    < Date: Tue, 21 Jun 2022 01:57:52 GMT
    <
  • Connection #0 to host graph.microsoft.com left intact
    {"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity","businessPhones":[],"displayName":"sync test 010","givenName":null,"jobTitle":null,"mail":"<censored>","mobilePhone":null,"officeLocation":null,"preferredLanguage":null,"surname":null,"userPrincipalName":"<censored>","id":"14e06f7c-57ac-424a-be45-63504546b6a2"}
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,033 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 45,186 Reputation points
    2022-06-21T07:55:35.71+00:00

    Hi @Kuo Ian

    Is the user you logged into Graph Explorer a member of a team? Please call https://graph.microsoft.com/v1.0/teams/{team id}/members api endpoint to view team members, if your user is not in a team then this is what is causing the problem reason.

    You need to add the logged in user to the team and then you should be able to send chat messages in the channel endpoint.

    213302-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.

    0 comments No comments

  2. Kuo Ian 1 Reputation point
    2022-06-21T09:26:23.37+00:00

    @CarlZhao-MSFT
    Hi, thank you for the suggestions.
    I sent a request to the team members endpoint and confirmed that the user with id <14e06f7c-57ac-424a-be45-63504546b6a2> is in the team.
    Following is a partial response from the team members:

    {
    "@odata.type": "#microsoft.graph.aadUserConversationMember",
    "id": "MCMjMSMjNTFhZWUwZjItMDg4ZC00ZDYyLWFhNmItZThiYzU3NzU3YzQ5IyMzMjFmNmExMC0xOWYyLTRlODktYThhNC02N2IwN2JkOGYxODkjIzE0ZTA2ZjdjLTU3YWMtNDI0YS1iZTQ1LTYzNTA0NTQ2YjZhMg==",
    "roles": [],
    "displayName": "sync test 010",
    "visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
    "userId": "14e06f7c-57ac-424a-be45-63504546b6a2",
    "email": "******@ejantest.onmicrosoft.com",
    "tenantId": "51aee0f2-088d-4d62-aa6b-e8bc57757c49"
    }

    Which fit the above /me endpoint results.

    0 comments No comments

  3. Srinivasa Rao Darna 6,761 Reputation points Microsoft Vendor
    2022-06-21T10:37:18.833+00:00

    Hi @Kuo Ian ,

    Can you verify the following?

    • Are you able to post a message in teams channel from teams client/web client with the same user you logged into Graph Explorer
    • User is a member of Teams
    • User is a member of Channel(if it is a private Channel)
    • Channel settings are set to "Anyone can post messages" if the user is only a member of teams/channel(for private channels)

    Hope this helps.

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