Description
Hi! I try to change user avatar from powershell script, but get error 400 invalid request and error on RC log “must NOT have additional properties [invalid-params]”. I think my request body wrong, but i dont now where, thx.
I tried this
$Uri = "http://address/api/v1/users.setAvatar"
$headers = @{
"X-Auth-Token" = "mytoken"
"X-User-Id" = "myid"
"Content-type" = "application/json"
}
$formData = @{
image = "path to image"
username = "username"
} | ConvertTo-Json
Write-Output $formData
$response = Invoke-RestMethod -Headers $headers -Uri $Uri -Method POST -Body $formData -ContentType 'application/json'
$response | ConvertTo-Json
Write-Output $response
Or this
$rocketchatUrl = "addres"
$username = "username"
$avatarPath = "path to pic"
$avatarBytes = [System.IO.File]::ReadAllBytes($avatarPath)
$base64EncodedAvatar = [System.Convert]::ToBase64String($avatarBytes)
$headers = @{
"X-User-Id" = "my id"
"X-Auth-Token" = "my token"
}
$jsonData = @{
"image" = "data:image/png;base64,$base64EncodedAvatar"
"username" = $username
} | ConvertTo-Json
Write-Output $jsonData
$response = Invoke-RestMethod -Uri "$rocketchatUrl/api/v1/users.setAvatar" -Method Post -Headers $headers -Body $jsonData -ContentType "application/json"
$response | ConvertTo-Json
Server Setup Information
- Version of Rocket.Chat Server: 5.4.2
- Operating System: Ubuntu server 20.04
- Deployment Method: tar
- Number of Running Instances: 1
- NodeJS Version: 14.19.3
- MongoDB Version: 5.0.18