我需要通过Powershell命令将现有(已部署的) API应用程序添加到API管理服务中。当我使用‘’命令尝试它时,它将创建新的API,但它没有导入这些操作。从文件或URL导入API有很多种方法,但是我需要添加现有的API,我遵循https://learn.microsoft.com/en-us/powershell/resourcemanager/apimanagement.servicemanagement/v1.1.4/new-azurermapimanagementapi链接,有没有方法将现有的API应用程序添加到API管理服务?
请求是-
https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxx/providers/Microsoft.ApiManag
ement/service/xxxxxxxxxx/apis/xxxxxxxxxxxxxxxxxxxxx?api-version=2016-10-10
Headers:
Body:
{
"name": "test",
"serviceUrl": "https://test.azure-api.net/",
"path": "test",
"protocols": [
"Http",
"Https"
],
"type": "Http"
}我正在寻找以API后缀、API应用程序、名称作为参数的命令
发布于 2017-03-27 08:39:56
因此,您可以通过描述这里的REST调用来实现这一点。
要获得承载令牌,请使用以下powershell代码:
$body = @{
client_id= '{Azure AD Application GUID}'
client_secret = '{Azure AD Application secret}'
grant_Type = 'clientcredentials'
resource = 'https://graph.windows.net/'
}
$result = iwr https://login.microsoftonline.com/{Azure_AD_Tenant_GUID}/oauth2/token -Method Post -Body $body
$BearerToken = ($result.Content | ConvertFrom-Json).access_tokenAzure AD应用程序服务主体应有权进行API管理,并发出以下REST调用:
$url = 'https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxx/providers/Microsoft.ApiManagement/service/xxxxxxxxxx/apis/xxxxxxxxxxxxxxxxxxxxx?api-version=2016-10-10&import=true&path=xxx'
$headers = @{'Content-Type' = 'application/vnd.swagger.link+json'; 'Authorization' = $BearerToken}
$body = {
"name": "test",
##### serviceUrl needs a link to SWAGGER.JSON, not to the root of the api #####
"serviceUrl": "https://test.azure-api.net/swagger.json",
"path": "test",
"protocols": [
"Http",
"Https"
],
"type": "Http"
}URL中的path查询参数是与此API关联的associated后端服务的名称。
如果您想在请求中添加API模式,您可以这样做,但可以用您的swagger模式替换请求的主体,并用vnd.swagger.doc+json替换“Content”头。
ps。也许对于Authorization头,您需要以下内容:"Bearer " + $BearerToken
https://stackoverflow.com/questions/43039556
复制相似问题