Hi @Pradip Kumbhar in the meantime, you could add the file to Teams via the client and get the url then reference that in the contentUrl
field.
I hope this helps,
Diana.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to send csv file to MS teams channel using graph API with below document;
https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-beta&tabs=http
This is working but I want to skip file uploading to SharePoint and send it directly to the channel by using the following document but getting error message:
In this document as it is mentioned to give content-type as "file" and contentUrl with base64 encoding of the file. Below is my code:
Method: POST
EndPoint: https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channel id}/messages
Request Body:
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"1\"></attachment>"
},
"attachments": [
{
"id": "1",
"contentType": "file",
"contentUrl": "U2VudCBTdW5kYXkgYXQgMDg6MzA6MjYKCldlZWtseSBTdGF0dXMgUmVwb3J0ClRvdGFsIE91dHN0YW5kaW5nIFJlcXVlc3QsMTcKQ2xvc2VkIHRoaXMgd2VlaywyClJlcXVlc3QgT3BlbiBNb3JlIFRoYW4gNSAgIGRheXMsMTcKVW5hc3NpZ25lZCwxCgpZRFQKQ2xvc2VkIFJlcXVlc3RzLDI0Ck9wZW4gTW9yZSBUaGFuIDUgZGF5cywxNwoKQXNzaWduZWUsVG90YWwgIyBvdXRzdGFuZGluZyBvZiByZXF1ZXN0LENsb3NlZCB0aGlzIHdlZWssT3BlbiBtb3JlIHRoYW4gNSBkYXlzCiwxLDAsMApKYWNrIFF1aW50b24sNSwwLDUKSmFzb24gUGFsb21pbm8sMTEsMiwxMQpWZW5rYXQgQnVsdXN1LDEsMCwxCg==",
"name": "report4.csv",
"content": ""
}
]
}
Response:
{
"error": {
"code": "BadRequest",
"message": "Failed to process content in attachment with Id '1'.",
"innerError": {
"date": "2021-03-24T05:50:12",
"request-id": "baeab6b4-92f9-4a56-b8d9-9697fd0d4423",
"client-request-id": "f0190d39-1e83-63f2-ec50-ddba0078f15f"
}
}
}
Hi @Pradip Kumbhar in the meantime, you could add the file to Teams via the client and get the url then reference that in the contentUrl
field.
I hope this helps,
Diana.
Copying answer from comments for better understanding
Finally, I am able to figure out the issue, 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
Correct URL Path:
https://nowlabcorp.sharepoint.com/:x:/r/Shared%20Documents/report.csv
please check :https://learn.microsoft.com/en-us/answers/questions/335233/sorry-this-file-has-been-deleted-or-moved-teams-gr.html