Invoke Rest Method to add new database and role for existing user

Reg :how to append or add a database , role for existing user using invoke rest method in powershell?

I have a project named project1 in Atlas mongodb. Inside project 1 , i have username and databasenames@ roles. i used invoke rest method post to create a new user as below

project name: project1 -> usera(username) -> marketing@read(databasename@rolename)

$newusr = @{
databaseName = 'admin'
password = $pwd
username = usera
roles = @(
@{
databaseName = marketing
roleName = read
}
)
}
Json = $newusr | ConvertTo-Json
$newusrUri = "https://cloud.mongodb.com/api/atlas/v1.0/groups/$projectId/databaseUsers"
Invoke-RestMethod -Method POST -Uri $newusrUri -Headers @{Authorization = "Basic $base64AuthInfo"} -ContentType "application/json" -Credential $credential -Body $Json
Now , for usera(existing user), i want to add a new database with roles -> sales@read

I used Get Method to check for existence of user in the project; if the user exists , i am trying to add or append new db with roles.I used POST method and it failed as user already exists. i tried below PATCH command , which actually modified the existing database&roles instead of adding new database&roles for same user

$update = @{
roles = @(
@{
databaseName = $dbname
roleName = $rolename
}
)
}
$updateJson = $update | ConvertTo-Json
$updateusrUri = "https://cloud.mongodb.com/api/atlas/v1.0/groups/$projectId/databaseUsers/admin/usera"
Invoke-RestMethod -Method PATCH -Uri $updateusrUri -Headers @{Authorization = "Basic $base64AuthInfo"} -ContentType "application/json" -Credential $credential -Body $updateJson
Please provide your suggestions or which method should we use while adding a new database , roles to existing user using invoke rest method in power shell. Thank you!!

I tried adding new database with roles for existing user using put method

Existing entry : usera read@marketing

New Entry with Put Method : I tried below command

$params = @{
"databaseName"="admin"
"password"="changeme123"
"username"="usera"
"roles"= @(
@{
"databaseName"="sales";
"roleName"="read"
}
)
}
$body = ConvertTo-Json -InputObject $params
$getProjectUri = "https://cloud.mongodb.com/api/atlas/v1.0/groups/5e3c30c1c56c98da14781a87/databaseUsers/admin/usera"
Invoke-RestMethod -Method put -Uri $getProjectUri -Headers @{Authorization = "Basic $base64AuthInfo"} -ContentType "application/json" -Credential $credential -Body $body
Error Message : Invoke-RestMethod : The remote server returned an error: (405) Method Not Allowed.
Please help in adding a new database with role for existing user , Thankyou!!

Refer to the API documentation, like posted in your other thread asking the same thing:

https://powershell.org/forums/topic/invoke-rest-method-in-powershell/