I have an application which can create emails with HTML formatting and embedded images. This works by adding an "attachments" section in the message create json like so:
"attachments": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "image.png",
"contentId": "48132221018252368",
"isInline": true,
"contentType": "image/png",
"contentBytes": "iVBORw0KGgoAAAA..."
}
]
However using a similar method when creating a calendar event does not work - there is no attachment if I query the event for attachments and the event view in Outlook shows a broken image.
So I tried adding the attachment after the event is created and I get a 201 success response as expected, with appropriate attachment data. But the attachment is still not there if I query for it.
So I tried adding the attachment by hand (i.e. not in my app) using the MS Graph API explorer but providing exactly the same request json as my app and the attachment is added as required and shows correctly in the event body.
A strange thing also happens if I create the attachment using my app (and it doesn't show), but I then delete the event through the API - the cancellation notice in Outlook shows my embedded image as expected.
What am I doing wrong?
- Why can't I add the attachment for an event in the same way as I do for an email?
- Why does the attachment get added correctly when done manually? Do I have to wait for some time (how long?) before I add it in my app?
- Why does the attached image show correctly when the event is deleted?
Note: I have only used very small images for testing, so the problem shouldn't be due to the file size being >3MB and therefore requiring a separate createUploadSession