Send chat message with attachment in teams channel

Copper Contributor

Trying to post chat message with attachment in teams channel using graph API. We are able to post the message successfully but when try to preview the attachment we are seeing a message please find the screenshot below. Please suggest a way to resolve this issue.

 

tried request to post using graph call:

POST https://graph.microsoft.com/v1.0/teams/{teamsId}/channels/{channelId}/messages 

 

{ 

    "body": { 

        "contentType": "html", 

        "content": "Test with Graph Attachment. <attachment id=\"{eTag}\"></attachment>" 

    }, 

    "attachments": [ 

        { 

            "id": "{eTag}", 

            "contentType": "reference", 

            "contentUrl": "{SPO Attachment URL}", 

            "name": "Test Versions.docx" 

        } 

    ] 

} 

Image.png

25 Replies
@Sai06 - We are investigating your query. We will update you soon.
Hi Team,
Any update on chat attachment issue?
@Sai06 - Have you used correct contentURL? Can you please hit that contentURL in browser and check the file is opening or not?
@Sai06 - Can you please check the attachment id which you used its unique. Not previously used.
In your graph call the attachment name is "Test Versions". But the file which you have opened its with different name.
Can you please check with new attachment id? Please let us know if you are still facing this issue?
@Sai06 - Can you please check the attachment id which you used its unique. Not previously used.
Can you please check with new attachment id? Please let us know if you are still facing this issue?

@Nivedipa-MSFT  - I have tried again as mentioned but still issue remains the same.

@Sai06 - There was an issue with View ID and Content URL.

The vieweId should be documented source ID, it will be visible in browser with the label "sourcedoc".

In the case of the root site, we need to provide /:x:/r/ in addition to the file path


Example for Correct URL Path:
https://domainname.sharepoint.com/:x:/r/Shared%20Documents/report.doccx

Can you please change accordingly and check again?

@Nivedipa-MSFT - I have made the changes that you have suggested, but still the issue persist.
We are trying to access a document from document library in a sub-site.

Would that change the format of the url?

Below are the url's I have tried:
url: https://domainname.sharepoint.com/:x:/r/sites/sharedDocuments/IT.docx
Request body:
{
"body": {
"contentType": "html",
"content": "Sharepoint File Attachment. <attachment id=\"E8D71CE3-1EF1-4301-8D09-2228EC90C605\"></attachment>"
},
"attachments": [
{
"id": "E8D71CE3-1EF1-4301-8D09-2228EC90C605", => Source Id
"contentType": "reference",
"contentUrl": "https://domainname.sharepoint.com/:x:/r/sites/sharedDocuments/IT.docx",
"name": "IT.docx"
}
]
}

Hi Team,
Any update on above issue?
@Sai06 - Could you please check your file path in sharepoint and use the same in the URL?

@Nivedipa-MSFTAs mentioned in above chat discussion we have tried different forms of SharePoint file path URL but still our issue exist. Please find the document below for different scenario's tried.

 

 

Hi Team,
Any update on chat attachment issue?

@Sai06 -
We have tested this API. It was working fine at our end. The attachment has uploaded successfully in channel.

NivedipaMSFT_0-1665469858853.png

NivedipaMSFT_1-1665469895045.png

 

Could you please verify the below points:
1. The file must already be in SharePoint.
2. To find the file properties, GET the 
driveItem for the file.
    For example, /drives/{id}/items/{id}.
    Your attachment ID is the GUID in the 
eTag of the driveItem.
    Your attachment 
contentURL is the webUrl of the driveItem's folder plus   the driveItem's  name.         
    Your attachment name is the 
driveItem's name.

Please let us know if you are facing any further issue?

@Nivedipa-MSFT  - We are able to upload the file successfully to the channel. But the issue is when we are trying to preview the file from the channel.

Please could you confirm that you are able to preview the file from the corresponding channel where its been posted/attached.

@Sai06 - We are able to repro your issue. We have raised a bug for it. We will let you know once we have any update on it.
Hi Team,
Any Update on the bug raised?

Hi Team,

Can you provide me the bug number raised for the above issue?

 

@Nivedipa-MSFT, I am following up on behalf of @Sai06
Do you have any update on this bug?
Also, can you share any bug id if possible so that we can have a track of its release?