0
votes

I am able to get the attachment info of the MSTeam chat using following beta version API https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages/{message-id}/replies/{reply-message-id}

for e.g. https://graph.microsoft.com/beta/teams/e7884ec9-cbf3-4661-b74a-6fc42ac34ce1/channels/19:[email protected]/messages/1600060770982/replies/1600061187436 gives

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('e7884ec9-cbf3-4661-b74a-6fc42ac34ce1')/channels('19%3A6a04c17090e249319b3731cbe72e6085%40thread.tacv2')/messages('1600060770982')/replies/$entity",
    "id": "1600061187436",
    "replyToId": "1600060770982",
    "etag": "1600061187436",
.....
    "attachments": [
        {
            "id": "40ce4e84-6e47-43ed-acb9-9edcddff5ef4",
            "contentType": "reference",
            "contentUrl": "https://.......1/Shared Documents/General/MsteamchatHistory Documentation.docx",
            "content": null,
            "name": "MsteamchatHistory Documentation.docx",
            "thumbnailUrl": null
        }
    ],
    ......
}

Not able to download using ContentUrl, hence finding the ways to get downloadURL so that it can be downloaded using HttpWebRequest.

One way to get download URL is by using https://graph.microsoft.com/v1.0/groups/{group-id-for-teams}/drive/items/{item-id}

for e.g. https://graph.microsoft.com/v1.0/groups/e7884ec9-cbf3-4661-b74a-6fc42ac34ce1/drive/items/012PWSBOUEJ3HEAR3O5VB2ZOM63TO76XXU

which gives

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('e7884ec9-cbf3-4661-b74a-6fc42ac34ce1')/drive/items/$entity",
    "@microsoft.graph.downloadUrl": "https://nepa1.sharepoint.com/sites/Venio1/_layouts/15/download.aspx?UniqueId=40ce....0&ApiVersion=2.0",
    "createdDateTime": "2020-09-14T05:26:14Z",
    "eTag": "\"{40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4},2\"",
    "id": "012PWSBOUEJ3HEAR3O5VB2ZOM63TO76XXU",
    "lastModifiedDateTime": "2020-09-14T05:26:21Z",
    "name": "MsteamchatHistory Documentation.docx",
    "webUrl": "https://nepa1.sharepoint.com/sites/Venio1/_layouts/15/Doc.aspx?sourcedoc=%7B40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4%7D&file=MsteamchatHistory%20Documentation.docx&action=default&mobileredirect=true",
    "cTag": "\"c:{40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4},3\"",
    "size": 563211,
    .....
}

Here I found the item-id by exploring groups. But I want the find the item id from the respective attachment id so that I can get the download URL for that attachment and used it to download using HttpWebRequest.

So, Is it possible to get the drive item-id from the attachment id? If yes, how can it be done?

Thanks in advance.

1

1 Answers

0
votes

One of my clients asked me this recently and I actually found a quick shortcut to making download links for SharePoint files. Since your Team attachments are being stored in a SharePoint folder (according to the URL), you should be able to use this trick too.

Using the Content URL, add &download=1, ?download=1, or ?Web=0 to the end of the URL like this:

https://.......1/Shared Documents/General/MsteamchatHistory Documentation.docx?download=1

and the link turns into a direct download link!

I haven't found any info about why this works and why sometimes one ending will work and the others won't, but so far, at least one ending has worked for all the files I've tested.