Hello Folks,
we have here "Invalid API version requested" after starting workflow "Invoke a REST host" on Orchestrator:
2023-02-03 09:05:20.494 +01:00INFO__item_stack:/item0
2023-02-03 09:05:20.509 +01:00INFOHost: DynamicWrapper (Instance) : [RESTHost]-[class com.vmware.o11n.plugin.rest.RESTHost] -- VALUE : RESTHost [name=vCD-API-36.x-provider, id=10f2e9b5-e492-4993-a182-ebf9bcb5156b, url=https://vcloud.domain.de/api, connectionTimeout=30, operationTimeout=60, hostVerification=false, proxyHost=, proxyPort=0, schemaRepo=com.vmware.o11n.plugin.rest.schema.SchemaRespository@72dc35ad, resourceId=null, privateKeyId=null], operation: /sessions, Request Type: undefined
2023-02-03 09:05:20.515 +01:00INFOrequest: https://vcloud.domain.de/api/sessions
2023-02-03 09:05:20.529 +01:00INFOresponse: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error xmlns=http://www.vmware.com/vcloud/v1.5 xmlns:vmext=http://www.vmware.com/vcloud/extension/v1.5 xmlns:ovf=http://schemas.dmtf.org/ovf/envelope/1 xmlns:vssd=http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData xmlns:common=http://schemas.dmtf.org/wbem/wscim/1/common xmlns:rasd=http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData xmlns:vmw=http://www.vmware.com/schema/ovf xmlns:ovfenv=http://schemas.dmtf.org/ovf/environment/1 xmlns:ns9=http://www.vmware.com/vcloud/versions message="The request has invalid accept header: Invalid API version requested. Supported API versions are: [37.0.0-alpha, 36.2, 36.1, 36.0, 35.2, 35.0, 34.0, 33.0 [D], 32.0 [D], 31.0 [D]] ([D] indicates deprecated versions)" majorErrorCode="406" minorErrorCode="NOT_ACCEPTABLE"/>
2023-02-03 09:05:20.538 +01:00INFO__item_stack:/item1
The Plug-In of vCloud Director in Orchestrator Control Center is the latest one and supports version 36.2. The vCloud Director have the same version. Why am I getting this error message? How i can solve this?
Best regards,
phoenix81
Try this:
#!/usr/bin/pwsh
$Global:vcdURL = "https://my.host.net/api"
$geheim= ( Get-Secret -Name vcd-api@my.host.net -AsPlainText )
$Pair = "vcd-api@system:$geheim"
$Bytes = [System.Text.Encoding]::ASCII.GetBytes($Pair)
$base64 = [System.Convert]::ToBase64String($Bytes)
$Authorization = "Basic $base64"
$headers = @{
Authorization = $Authorization
"Accept" = "application/*+xml;version=36.2"
}
#$headers
$MyRequest = Invoke-WebRequest -uri $Global:vcdURL/api/sessions -Method Post -header $headers
$Global:vCDToken = ($MyRequest.Headers.'X-VMWARE-VCLOUD-ACCESS-TOKEN')
$Global:vCDxvcloud = ($MyRequest.Headers.'x-vcloud-authorization')
Global:vCDHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Global:vCDHeaders.Add("Accept", "application/json;version=36.2")
$Global:vCDHeaders.Add("Authorization", "Bearer $($Global:vCDToken)")
Hello phoenix81.
Version 36.2 has a different authorization link.
https://developer.vmware.com/apis/vmware-cloud-director/v36.2/cloudapi/1.0.0/sessions/post/
Try this:
#!/usr/bin/pwsh
$Global:vcdURL = "https://my.host.net/api"
$geheim= ( Get-Secret -Name vcd-api@my.host.net -AsPlainText )
$Pair = "vcd-api@system:$geheim"
$Bytes = [System.Text.Encoding]::ASCII.GetBytes($Pair)
$base64 = [System.Convert]::ToBase64String($Bytes)
$Authorization = "Basic $base64"
$headers = @{
Authorization = $Authorization
"Accept" = "application/*+xml;version=36.2"
}
#$headers
$MyRequest = Invoke-WebRequest -uri $Global:vcdURL/api/sessions -Method Post -header $headers
$Global:vCDToken = ($MyRequest.Headers.'X-VMWARE-VCLOUD-ACCESS-TOKEN')
$Global:vCDxvcloud = ($MyRequest.Headers.'x-vcloud-authorization')
Global:vCDHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Global:vCDHeaders.Add("Accept", "application/json;version=36.2")
$Global:vCDHeaders.Add("Authorization", "Bearer $($Global:vCDToken)")
Macleud: Thanks for this. I will check it.
moellerjot: thanks for this. I will try it.
$response = (Invoke-WebRequest -TimeoutSec 60 -Uri "$GLOBAL:vcdAPI$ApiUri" -SkipCertificateCheck -Headers $Global:vCDHeaders -Method $Method -ErrorAction SilentlyContinue)