question

KedarKekan-9646 avatar image
0 Votes"
KedarKekan-9646 asked YukiSun-MSFT edited

Download files shared on public channel

I am using microsoft teams api to fetch public channel message. With messages I also get attachments with a sharepoint URL as content URL. Now i want to download that file but it fails to download it. If i directly copy paste contentURL on browser, it downloads the file but if i do an http call, it fails. I cannot use sharepoint graph api(download by item ID) as i don't get itemID here. Is there any way to download those file? Any permission needed or any mistake i am doing on HTTP call?

office-teams-windows-itpromicrosoft-graph-teamwork
· 1
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 @KedarKekan-9646,

Welcome to Microsoft Q&A!

The “office-teams-windows-itpro” tag is for general questions about Teams client. Since from the description, your question involves using Microsoft Teams api, I’ll add the tag “Microsoft-graph-teamwork” so that their community members can help look into it as well. Thanks for your understanding.

1 Vote 1 ·

1 Answer

SrinivasaRaoDarna-MSFT avatar image
1 Vote"
SrinivasaRaoDarna-MSFT answered KedarKekan-9646 commented

Hi @KedarKekan-9646,

Based on the description, there is no one shot API call you can make to get file content from teams channel post.

GET /teams/{teamId}/channels/{channelId}/messages and from response object attachments/contentUrl you can use the File Path relative to the root.

Step 1: From below path relative to root General/Sample.csv.
206113-865284-filepath.jpg


Step 2: You can make a another graph request with /groups/{teamId} or /sites/{siteId} and get item using filePath and fetch the id from the response object.

 GET /groups/{teamId}/drive/root:/General/Sample.csv

206104-865284-itemid.jpg


Step 3: Use id from above, and download file content using /groups/{teamId}/drive/items/{itemId/content

Note: I am using /groups/{teamId} as I can use teamId as groupId and get groups drive, and I don't have make another Graph API call to get SharePoint site by path or id.

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


865284-filepath.jpg (25.0 KiB)
865284-itemid.jpg (56.1 KiB)
· 1
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.

Thanks @SrinivasaRaoDarnaMSFT-7657 It worked exactly we wanted to work.

0 Votes 0 ·