Azure:在没有服务 URL 的情况下创建新的 API 管理服务

Azure: create a new API Management service without a service URL

我的目的是将 API(例如 Azure 函数)配置为 API 管理服务 仅使用 政策。我不想指定 服务 URL

这可以使用 Portal UI:

但未使用 PowerShell Az 模块。

以下代码:

New-AzApiManagementApi -Context $context -Name $fullName -Protocols @('https') `
                                         -Path $path -ProductIds @($product) `
                                         -ApiVersionSetId $apiMgmtVersion.ApiVersionSetId

引发此异常:

Error : Unable to create 'news' managed API version 1.
Cannot validate argument on parameter 'ServiceUrl'. The argument is null or empty. Provide an argument that is not null or empty, and then try the 
command again.
At C:\Projects\Intranet.ai\component_tools\Install-ApiMgmt.ps1:105 char:76
+ ... able to create '$fullName' managed API version $version.`n$_" | Error
+                                                                     ~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Error

有没有办法在没有服务 URL 的情况下定义 API?也许直接使用 New-AzResource?

感谢任何愿意提供帮助的人!

Is there a way to define an API without a service URL? Maybe using directly New-AzResource?

New-AzApiManagementApi好像不支持,你可以直接用New-AzResource,请试试下面的例子,我这​​边很管用。

$PropertiesObject = @{
        "name" = "test22"
        "serviceUrl" =  $null
        "path" = "testaaa"
        "protocols" = @("https")
    }
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName <Group-name> -ResourceType Microsoft.ApiManagement/service/apis -ResourceName "<API-management-servie-name>/test22" -ApiVersion 2018-01-01 -Force

登录门户:

更新:

如果您想要包含 apiVersionSetId,请尝试以下选项。

$versionSet = Get-AzApiManagementApiVersionSet -Context $context -ApiVersionSetId "d41e7f92-9cf8-48fb-8552-d9ae5d4690d3"
$Id = $versionSet.Id -replace "apiVersionSets","api-version-sets"

$PropertiesObject = @{
        "name" = "test22"
        "serviceUrl" =  $null
        "path" = "testaaa"
        "protocols" = @("https")
        "apiVersionSetId" = $Id
    }
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName <Group-name> -ResourceType Microsoft.ApiManagement/service/apis -ResourceName "<API-management-servie-name>/test22" -ApiVersion 2018-01-01 -Force