Forgot to convert to plain string; $($sessionId)
$sessionId is the Object, need to use the String
Leaving this here for future reference, took me about an hour to realize my mistake
Using Powershell for this;
Code: Select all
$User = "myusername"
$Password = "mypassword"
$Auth = "$($User):$($Password)"
$Auth64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$Auth"))
$BaseURI = "sub.domain.tld"
$Uri = "http://$($BaseURI):9399"
$Response = Invoke-WebRequest -Method POST -Uri "$URI/api/sessionMngr/?v=latest" -Headers @{'Authorization'= "Basic $Auth64"}
$SessionId = $Response.Headers.'X-RestSvcSessionId'
Code: Select all
$BackupServerReferenceList = (([xml]$response.Content).LogonSession.Links.Link | where-object {$_.Type -eq 'BackupServerReferenceList' }).Href
$response = Invoke-WebRequest -Uri $BackupServerReferenceList -Method "GET" -Headers @{"X-RestSvcSessionId" = $sessionId}
# I get this response';
## Invoke-WebRequest : Response status code does not indicate success: 401 (Unauthorized).
REST Api log says;
Code: Select all
[07.09.2019 13:04:29] <43> Error Failed to parse sessionId.
[07.09.2019 13:04:29] <43> Error The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. (System.FormatException)
[07.09.2019 13:04:29] <43> Error at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
[07.09.2019 13:04:29] <43> Error at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
[07.09.2019 13:04:29] <43> Error at System.Convert.FromBase64String(String s)
[07.09.2019 13:04:29] <43> Error at Veeam.Backup.Common.CStrUtil.ConvertFromBase64(String strText)
[07.09.2019 13:04:29] <43> Error at Veeam.Backup.Enterprise.RestAPIService.CRestOperationContext.String2Guid(String base64EncodedStr, Guid& sessionId)
[07.09.2019 13:04:29] <43> Error Failed to retrieve backup server references.. RequestUri: [http://enterpriseplus-backup.deviske.cloud:9399/api/backupServers].
[07.09.2019 13:04:29] <43> Error Identity was not authenticated. (Veeam.Backup.Interaction.RestAPI.CRestAPICommunicationException)
[07.09.2019 13:04:29] <43> Error at Veeam.Backup.Enterprise.RestAPIService.CRestApiLogonSessionsScope.ObtainSessionId()
[07.09.2019 13:04:29] <43> Error at Veeam.Backup.Enterprise.RestAPIService.CRestApiLogonSessionsScope.get_RestSession()
[07.09.2019 13:04:29] <43> Error at Veeam.Backup.Enterprise.RestAPIService.CEnterpriseRestServiceStub.GetBServerRefs()
[07.09.2019 13:04:29] <43> Error Identity was not authenticated.
What am I missing here?
I get the same result when performing this operation
Invoke-WebRequest -Method GET -Uri "http://sub.domain.tld:9399/api/backupServers" -Credential (Get-Credential) -AllowUnencryptedAuthentication
> Invoke-WebRequest : Response status code does not indicate success: 401 (Unauthorized).