RESTful knowledge exchange
Post Reply
PeterLouwerse
Service Provider
Posts: 16
Liked: never
Joined: Aug 09, 2012 8:06 am
Full Name: Peter Louwerse
Contact:

Unable to authenticate

Post by PeterLouwerse »

Hi all,

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
        }

    }
    
Any help appreciated

Thanks & regards
Peter Louwerse
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Unable to authenticate

Post by oleg.feoktistov »

Hi Peter,

Please double check your request method verb. Looks like you're using GET in your code, but /oauth2/token endpoint supports POST only.

Best regards,
Oleg
PeterLouwerse
Service Provider
Posts: 16
Liked: never
Joined: Aug 09, 2012 8:06 am
Full Name: Peter Louwerse
Contact:

Re: Unable to authenticate

Post by PeterLouwerse »

Bloody...

Thanks! Stared me in the face...must have been code blind. Note to self: don't simply copy/past a web request, take one that has the same function.

Cheers,

Peter
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests