Share via

Using Get Chat Graph API for ms Teams in Postman.

Alex Wilber 66 Reputation points
2020-07-28T08:02:28.447+00:00

Http : - https://graph.microsoft.com/beta/chats/{id}

sending the request then getting an error:-
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"date": "2020-07-28T07:55:53",
"request-id": "d11640a9-ebf9-4fee-b75d-6f3198cf6db3"
}
}
}

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments

Answer accepted by question author

  1. soumi-MSFT 11,861 Reputation points Microsoft Employee Moderator
    2020-07-31T05:57:39.537+00:00

    @Alex Wilber , Thank you for reaching out and sharing more details on this. So the problem lies basically in the grant_type that you have used here. Let's go step by step in details:

    You used the client_credential flow (using grant_type as client_credetantials) and you used the token issued by that call to call the /users graph API. This is correct and hence you got the response.

    But the point to check here is, you got the token in application's context when you used the client_credentials flow. Which would work for the /users API but not for the chats or conversations or such APIs. To call those APIs, you would need the token to be fetched from AAD using the Authorization-Code Grant flow (using the grant type as authorization_code)

    Now the following API: https://graph.microsoft.com/beta/users/{user-id}/chats would work only if the following conditions are met:

    1. You have proper Delegated permissions assigned to your app registration (for eg: Delegated permission - Chat.ReadBasic, Chat.Read, Chat.ReadWrite), Also you if you check the doc for this API "https://learn.microsoft.com/en-us/graph/api/chat-get?view=graph-rest-beta&tabs=http#permissions", you would find that it doesn't support Application permissions (which are used during the client_credentials flow)
    2. The user-id to be put in the API call should be the userId of the user who in whose context the token was issued. For eg: if you have authenticated yourself using the auth-code grant flow, in that case, the access-token would be issued in your user's context, and hence in the API call, only your user-id needs to be used.

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. If there are still some issues in getting the correct results, do drop us an email on azcommunity[at]microsoft[dot]com with the following details, and we would connect with you offline and discuss this in detail.

    Tenant ID/Tenant Name:
    Subscription ID:

    Do not forget to share the thread URL of this issue so that its easier for me to pick this up and help you further.

    Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. soumi-MSFT 11,861 Reputation points Microsoft Employee Moderator
    2020-07-30T11:21:00.047+00:00

    @Alex Wilber , Thank you for sharing the details. I just tested this api and let me share the screenshot first:
    14500-chats.png

    Now a few things that you would want to check are:

    1. Check if the user ID you have mentioned is your own user ID or User ID of the user who has requested the access-token that is being sent as bearer while making the api call.
    2. Try using the /me endpoint (GET https://graph.microsoft.com/beta/me/chats).
    3. Decode your token using the Jwt.ms tool and check for the key "scp" and check if that key contains the value "Chat.Read", as this is the key that is checked when the api decodes your token and tries to validate you permissions.

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.


  2. soumi-MSFT 11,861 Reputation points Microsoft Employee Moderator
    2020-07-30T05:51:32.787+00:00

    @Alex Wilber , Thank you for reaching out and I apologize for the delay in my response. I tried this API myself with Postman, and found that when I am using the scope as "chat.readwrite", I stumbled upon this same exact error. But when I modified the scope to chat.read, it worked fine. Do try with chat.read once and check if that works for you.

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.