Search code examples
microsoft-graph-apimicrosoft-teamsmicrosoft-graph-teams

Is there a way to post a message with a code snippet?


The new way to upload images as hosted content through the Send Message endpoint is great! However, is there a way to upload text/plain as hosted content in order to post a Code Snippet Card in a message? I have tried uploading text but the response gives me an error that says that the only content types allowed are 'image/jpg,image/jpeg,image/png'.

Example request:

{
    "body": {
        "contentType": "html",
        "content": "<attachment id=\"4d92eb51ab9c48ebb5b364794a2fa569\"></attachment>"
    },
    "attachments": [
        {
            "id": "4d92eb51ab9c48ebb5b364794a2fa569",
            "contentType": "application/vnd.microsoft.card.codesnippet",
            "contentUrl": null,
            "content": "{\"name\":\"\",\"language\":\"CSharp\",\"lines\":1,\"wrap\":false,\"codeSnippetUrl\":\"../hostedContents/1/$value\"}",
            "name": null,
            "thumbnailUrl": null
        }
    ],
    "hostedContents":[
        {
          "@microsoft.graph.temporaryId": "1",
          "contentBytes": "VGVzdA==",
            "contentType": "text/plain"
        }
    ]
}

Response:

{
    "error": {
        "code": "BadRequest",
        "message": "Unsupported content type in hostedContent with Id '1'. Allowed values are 'image/jpg,image/jpeg,image/png'",
        "innerError": {
            "date": "2020-10-07T12:17:15",
            "request-id": "ed24f5df-3e1f-4871-b430-e4c1c9f30348",
            "client-request-id": "ed24f5df-3e1f-4871-b430-e4c1c9f30348"
        }
    }
}

Solution

  • I received an answer in the Documentation GitHub: https://github.com/microsoftgraph/microsoft-graph-docs/issues/10210#issuecomment-705050649

    Code snippets are not supported at the moment. They are on list of things to support, but there is no timeline to share yet.