2

Using Microsoft Graph REST API, we create an Outlook calendar event

Focus on the body attribute:

{
  ...,
  "body": {
    "contentType": "text",
    "content": "Test\n\nTest"
  }
}

We would expect the event's description, as shown in Outlook Calendar and in Teams Calendar (Microsoft Teams > Calendar tab), to then be:

Test

Test

This is the case in Outlook calendar (outlook.com). However, in Teams Calendar, it displays as:

Test Test

We've also tried \r\nTest\r\n\r\nTest\r\n with the same result.

How can we have linebreaks in the description/body of the event we create, correctly displayed in Outlook and Teams?

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13
Konrad
  • 852
  • 11
  • 31

2 Answers2

2

According to the itemBody documentation of the event, you can also add it as html. Then you'll know for sure how it's is going to look.

{
  "body": {
    "contentType": "html",
    "content": "<h1>test</h1><br />\n<p>test</p>"
  }
}

Keep in mind that not all html is supported, but it should get you a long way. And "nice" html isn't really a requirement, so this would also work: test<br />\ntest

Stephan
  • 2,356
  • 16
  • 38
  • Thanks Stephan, but due to other implementations we would really like not to use HTML. Do you know if there is a solution in text? – Konrad Jul 09 '20 at 15:37
  • I'm no developer for teams, but my guess is that in teams (which is actually just a webapp with a shell around it) they just put the text in a div. Outlook actually renders the text. If you put `Test\n\nTest` in any html the `\n` is replaced by ` ` – Stephan Jul 10 '20 at 09:16
  • I see what you mean, unfortunately it does not help me solve my problem. According to you, would moving to HTML be the only viable solution? – Konrad Jul 10 '20 at 12:16
  • That is what I think, but I wouldn't say it's a big change. just change `text` to `html` and replace all your `\n` with `
    `. No need to change other things, as said it also supports "not so nice html".
    – Stephan Jul 10 '20 at 15:38
  • Basically we display this text elsewhere and HTML is not supported there, we would have liked not to have to apply yet another text transformation and have different formats of the same text. Will mark this as accepted if no better solution comes up. – Konrad Jul 10 '20 at 16:34
0

Simply change the contentType to HTML but use the exact text you have.

Based on my experiments this works correctly in both teams and outlook

GavinB
  • 515
  • 5
  • 15