For those using PowerShell the following has worked using the api ‘api/projects/update_visibility’.
Http:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = "<admin_user>"
$securedValue = Read-Host "Please Enter Password " -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue)
$value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
$combocred = "$($user):$($value)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($combocred))
$headers = @{"Authorization" = "Basic "+$encodedCreds}
Invoke-RestMethod -Uri "http://<sonarqubeurl>:9000/api/projects/update_visibility?project=<Project_Key>&visibility=private" -Method Post -Headers $headers -ContentType "application/json"
HTTPS:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = "<admin_user>"
$securedValue = Read-Host "Please Enter Password " -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue)
$value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
$combocred = "$($user):$($value)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($combocred))
$headers = @{"Authorization" = "Basic "+$encodedCreds}
Invoke-RestMethod -Uri "https://<sonarqubeurl>/api/projects/update_visibility?project=<Project_Key>&visibility=private" -Method Post -Headers $headers -ContentType "application/json"