Failed to process request when sending a message with an attachment (Microsoft Teams Graph API)

Viewed 124
Code: BadRequest
Message: Failed to process request.
Inner error:
    AdditionalData:
    request-id: 768916ef-e040-42eb-aaa3-9ac5745f9224
    date: 2020-02-27T08:01:48
ClientRequestId: 768916ef-e040-42eb-aaa3-9ac5745f9224

Hi I keep getting the above error anytime I attach a file to a chatMessage when sending a message on a Teams channel. I am using the Teams path anyway. My example code below.

Am I missing something.

//  Base64 encoding of the file in data
            byte[] bytes = System.IO.File.ReadAllBytes(ContentUrl);
            string file = Convert.ToBase64String(bytes);



            // Make a channel chat message object
            var chatMessage = new ChatMessage()
            {
                Subject = null,
                Body = new ItemBody
                {
                    ContentType = BodyType.Html,
                    Content = constructedMsg
                },
                Attachments = new List<ChatMessageAttachment>()
                {
                    new ChatMessageAttachment
                    {
                        ContentType = "image/jpeg",
                        ContentUrl = file,
                        Content = null,
                        Name = null,
                        ThumbnailUrl = null
                    }
                }
            };

await _graphClient.Teams[teamId].Channels[channelId].Messages.Request().AddAsync(chatMessage);
0 Answers
Related