Downloading files/images/attachments from existing Microsoft Teams "Chat"s through Graph API

Adz 286 Reputation points
2021-12-09T23:22:53.447+00:00

I have a requirement where I need to download files/images/attachments from an existing Microsoft Teams Chat (s) so I have a few questions...

I've got my "way" of doing this, but I'm not sure if it's the "best" way so I suppose I am (please) asking you for some guidance on how to do this correctly.

With regards to my solution for downloading images of a one-on-one Chat I do these calls

  1. GET /chats (this returns all one-on-one chats for the current user)
  2. GET /chats/{chat-id}/messages
  3. GET /chats/{chat-id}/messages/{message-id}/hostedContents
  4. GET /chats/{chat-id}/messages/{message-id}/hostedContents/{hosted-content-id}/$value

Now with regards to attachments, the documentation states "chatMessageHostedContent resource type. Represents Teams content hosted in a chat message, such as images or code snippets. File attachments are not hosted content; they are stored in SharePoint or OneDrive."

So if I understand this right, if I attach a .pdf file in a Chat, this gets stored in SharePoint or OneDrive. In my use case the JSON response (when i get a list of one-on-one Chat messages or a specific message) has an "attachments" array which contains an "id" and "contentUrl" that has a SharePoint URL (for a .pdf file in this case). Is there an endpoint I can hit with the attachment."id" to download the content value? If not what is the recommended way to download the actual content?

So regarding this, I've also got a few mores questions if you could please try to answer:

  • Is it possible to get a list of all Chat (s) of an organisation? According to this it's a no -> https://stackoverflow.com/a/62912307 (from the time of this writing this was over a year ago however)
  • Is there a "better way" of downloading all files/attachments/images of an existing one-on-one chat through the Graph API than from the way I'm trying to do it?
  • Do all file attachments go to the "Files" tab in a one-on-one Chat (is this hosted on SharePoint or OneDrive?) ?
    • 156435-chat-files-tab.png

For any future messages that comes through a Chat I guess I can create a subscription to see the message and attachments that are occurring as per the docs here https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0&tabs=http .

Microsoft Teams | Development
Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

Accepted answer
  1. JimmyYang-MSFT 58,646 Reputation points Microsoft External Staff
    2021-12-10T07:29:15.733+00:00

    Hi @Adz

    Considering your question also related to Teams API development, I will also add teams-app-dev tag to your thread. For Teams api question, someone who familiar it will give you more insights.

    Do all file attachments go to the "Files" tab in a one-on-one Chat (is this hosted on SharePoint or OneDrive?) ?

    Files that you upload to a channel are stored in your team's SharePoint folder. These files are available in the Files tab at the top of each channel.

    Files that you upload to a one-on-one or group chat are stored in your OneDrive for Business folder and are shared only with the people in that conversation.


    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.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.