RESTful knowledge exchange
Post Reply
rolflobker
Service Provider
Posts: 22
Liked: 4 times
Joined: Oct 13, 2016 6:52 pm
Full Name: Rolf Lobker
Contact:

[RESOLVED] 401: Unauthorized on VEM

Post by rolflobker » 2 people like this post

RESOLVED:
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'
# This gives me a Session ID which I am supposed to send on each subsequent request;

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.
But the SessionID provided is the same one as received in the Header when performing the logon request.

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).
chris.arceneaux
VeeaMVP
Posts: 668
Liked: 359 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: [RESOLVED] 401: Unauthorized on VEM

Post by chris.arceneaux »

Hi Rolf,

Thanks for posting your resolution!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests