I'm working on a project that sends messages to Teams users automatically. This code works perfectly in PowerShell version 5.1, but when I try to use it in version 7.2, I get an error stating that it's missing body content. Here's the code I'm using:
```powershell
$params = @{
body = @{
contentType = "html"
content = "test"
}
}
New-MgChatMessage -ChatId $ChatDetails.Id -BodyParameter $params
```
But in version 7.2, I get the following error:
```
New-MgChatMessage_Create:
Line |
7 | New-MgChatMessage -ChatId $ChatDetails.Id -BodyParameter $params
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Missing body content
Status: 400 (BadRequest)
ErrorCode: BadRequest
Date: 2025-04-21T13:52:32
```
I've checked the service error codes, but I'm not sure what the issue is. Any insights?
4 Answers
You might want to check how you are referencing the body parameter. After `-BodyParameter`, try `$params.body` or you could even do `(($params.body) | ConvertTo-JSON)` to make sure it's properly formatted.
I noticed that the error message you posted doesn't quite match the snippet. Make sure you're actually calling the updated code when testing. It can sometimes behave differently in the ISE compared to running it directly in the terminal.
I've encountered a similar issue, and for version 7.2, it looks like you need to modify your command to ensure proper syntax:
```powershell
New-MgChatMessage -ChatId $($ChatDetails.Id) -BodyParameter $params
```
Make sure to use `$($ChatDetails.Id)` instead of just `$ChatDetails.Id`. It really seems to help with any missing content errors.
It looks like you're not passing the parameters correctly for version 7.2. Try this instead:
```powershell
$params = @{
ChatId = $ChatDetails.Id
Body = @{
contentType = "html"
content = "test"
}
}
New-MgChatMessage @params
```
This should fix the issue! Just a heads-up, I’m replying from my phone so formatting might be off a bit.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String