We're attempting to send emails with csv file attachments via the MS GRAPH API. Our process works fine for emails without attachments, but whenever we attempt to include the csv we receive the following Error 400:
The property 'ContentBytes' does not exist on type 'microsoft.graph.attachment'. Make sure to only use property names that are defined by the type or mark the type as open type.
The code we are using to generate the attachment:
message.Attachments = new Microsoft.Graph.MessageAttachmentsCollectionPage();
message.HasAttachments = true;
byte[] attachmentAsBytes = File.ReadAllBytes(fileDirectory + @"\filename.csv");
string asBase64 = Convert.ToBase64String(attachmentAsBytes);
message.Attachments.Add(new Microsoft.Graph.FileAttachment()
{
ODataType = "#microsoft.graph.fileAttachment",
Name = "filename.csv",
ContentType = "text/csv",
ContentBytes = Convert.FromBase64String(asBase64)
});
It seems like the API is incorrectly identifying the attachment as type "microsoft.graph.attachment" instead of the marked "microsoft.graph.fileAttachment." What am I missing/failing to understand about the ODataType
field or Graph API endpoint?