VMware Cloud Community
drogal
Contributor
Contributor
Jump to solution

VROPS API Login

Reference: https://docs.vmware.com/en/vRealize-Operations/8.6/com.vmware.vcom.api.doc/GUID-C3F0A911-A587-40F7-9...


According to the above, the following code should work. However, I get a HTTP/401.

$VROPS = 'https://vrops-server/suite-api/api'
$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName $env:USERNAME -Message 'VROPS Creds'
$username = $creds.UserName
$plaintext = $creds.GetNetworkCredential().password
$jsonBody = @{username="$username";password="$plaintext";authSource="DOMAIN"} | ConvertTo-Json
$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody



I have tried with and without authSource (that got me locked out, so definitely it's hitting the domain).

Also, I tried with "-Body $jsonBody.ToString()" just in case.

Labels (3)
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
drogal
Contributor
Contributor
Jump to solution

Thanks, here's the trick: USERNAME@AUTHSOURCE

USERNAME = username only, not username@domain.com
The AUTHSOURCE must be appended.

$VROPS = 'https://vrops_server/suite-api/api'
# Authentication Source Display Name
$AUTHSOURCE = 'AUTH_SOURCE_DISPLAY_NAME'


$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName "$($env:USERNAME)" -Message 'VROPS Creds'
$username = $creds.UserName + "@$($AUTHSOURCE)"
$plaintext = $creds.GetNetworkCredential().password

$jsonBody = @{username="$username";password="$plaintext"} | ConvertTo-Json

$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody

View solution in original post

Tags (1)
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Could this be the issue described in KB2103084?

Did you try the same with something like PostMan?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
drogal
Contributor
Contributor
Jump to solution

Thanks, here's the trick: USERNAME@AUTHSOURCE

USERNAME = username only, not username@domain.com
The AUTHSOURCE must be appended.

$VROPS = 'https://vrops_server/suite-api/api'
# Authentication Source Display Name
$AUTHSOURCE = 'AUTH_SOURCE_DISPLAY_NAME'


$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName "$($env:USERNAME)" -Message 'VROPS Creds'
$username = $creds.UserName + "@$($AUTHSOURCE)"
$plaintext = $creds.GetNetworkCredential().password

$jsonBody = @{username="$username";password="$plaintext"} | ConvertTo-Json

$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody
Tags (1)
0 Kudos