I'm trying to authenticate using the RESTful API (Veeam B&R v12) but whatever I try, I get the same error message:
Invoke-WebRequest: {"errorCode":"NotImplemented","message":"Unsupported RESTAPI version. The following versions are supported: v1.0-rev1, v1.0-rev2, v1.1-rev0","resourceId":null}
Code looks like this (using PowerShell classes):
Code: Select all
VBRSession([string]$server, [System.Management.Automation.PSCredential]$credential)
{
$this.username = $credential.username
$this.password = $credential.GetNetworkCredential().password
$this.server = $server
# Get a session token
[string]$tokenUrl = "https://" + $this.server + ":9419/api/oauth2/token"
$body = @{
"grant_type" = "password"
"username" = $this.username
"password" = $this.password
}
$headers = @{
"content-type"="application/x-www-form-urlencoded"
"x-api-version" = "1.1-rev0"
}
try {
$response = Invoke-RestMethod $tokenUrl -Method 'GET' -Headers $headers -Body $body -SkipCertificateCheck
$this.sessionToken = $response.access_token
}
catch {
write-host "Error making REST request to:`n" $tokenUrl -ForegroundColor Red
Write-Host "`nStatus Code:" $_.Exception.Response.StatusCode.value__ -ForegroundColor Red
Write-Host "Status Description:" $_.Exception.Response.StatusDescription -ForegroundColor Red
#exit
}
}
Thanks & regards
Peter Louwerse