microsoft-graph-apimicrosoft-graph-calendar

How to embed an image in a calendar event using MS Graph API


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?

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


Solution

  • The one step process where you create an inline attachment and the event in one request looks like its buggy as I can reproduce the same issue. As a workaround doing a 3 step process seems to work okay eg first create the event with no attendees or body. Step 2 add the attachment, step 3 patch the attendees and the body.