for me only works if I use token, I’m not sure how format to accept user credentials with base64 encoded password
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"password`": `"[base64 encoded password]`",`n `"username`": `"[APPUSER]`"}"
$response = Invoke-RestMethod 'https://localhost/webconsole/api/DDBInformation/8' -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
```Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:7 char:13
+ $response = Invoke-RestMethod 'https://localhost.local/webcon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
{`
It depends on the api. Try to see if there is any documentation for that API. Normally authentication is via Headers. You can try -Credential
of Invoke-RestMethod
to access the service.
this is the API Commvault Rest API - Public
it works when using QSDK token, I did try -Credential
I’m struggling with using the token in next command
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"password`": `"Base64 encoded password`",`n `"username`": `"USERNAME`",`n `"timeout`" : 30`n}"
$response = Invoke-RestMethod 'https://localhost/webconsole/api/Login' -Method 'POST' -Headers $headers -Body $body
$response.token
QSDK 0d3283f03e58e2e8d0cdd41b3720c25642a747e4b4ffab2b27e707ed90d3283f03e58e2
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authtoken", "QSDK 3cfd4430caf4158d60e84f1e978405342a4a67fccd06603325585697c296584d5c4ae8f581632e2f1a696d9a0fce2ad64f3d28601acea24f72b00b22bd1a2679bbc0a96c7b934b4222747c4cb2b4f3ea243b758b22b575bc841ea9688d34c310832b28d9a5f5c93a42bb195ca3869e9cc8dd43e000277d97c63789197cf113e1c4a1d55cdb9461adfb78fd5b7b9031f272b3b651846ab30766fcb61eb1fb193c1768d1dfff99508ba3cf68a8b8b2645b43e13da8aa1787cda42fa76dde71ac52a2e0207e66474b60ddabb20bf457aedf65cfbbe7335f957bd79e84433c9ae051f0fe5ae01f203d4183c87672ed945c5cc2c90d999107e906ef070505874485ef679b1d63736f22d26")
$headers.Add("Accept", "application/json")
$response = Invoke-RestMethod 'http://WebConsoleHostName/webconsole/api/DDBInformation/60' -Method 'GET' -Headers $headers
$response | ConvertTo-Json