Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell将现有API添加到Azure API管理服务_Powershell_Azure - Fatal编程技术网

使用powershell将现有API添加到Azure API管理服务

使用powershell将现有API添加到Azure API管理服务,powershell,azure,Powershell,Azure,我需要通过Powershell命令将现有(已部署)API应用程序添加到API管理服务。 当我尝试使用'New AzureRmApiManagementApi'命令时,它将创建新的API,但它没有导入操作。 有很多方法可以从文件或URL导入API,但我需要添加现有的API 我跟着林克 有没有办法将现有的API应用程序添加到API管理服务中 请求是- https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

我需要通过Powershell命令将现有(已部署)API应用程序添加到API管理服务。 当我尝试使用'New AzureRmApiManagementApi'命令时,它将创建新的API,但它没有导入操作。 有很多方法可以从文件或URL导入API,但我需要添加现有的API 我跟着林克 有没有办法将现有的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 URL后缀、API应用程序、名称作为参数的命令,这样您就可以通过所描述的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_token
Azure 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关联的API管理后端服务的名称

如果您想在请求中添加API模式,您可以这样做,但是用您的swagger模式替换请求的主体,并用
vnd.swagger.doc+json替换“Content Type”头


另外,对于
授权
标题,您可能需要以下信息:
承载人+$BearerToken

好吧,使用powershell肯定可以做到这一点,您可以发布powershell正在执行的http请求吗?你可以使用你的PopeS壳命令得到一个<代码> -Debug ./Calp>交换机(它将在所有输出的中间)@ 4C7356B41,在S问世中提到的,除非有其他的PopeS壳命令你不走运,你可以使用REST来做这件事,如果你不能理解这一点,我可以在一个小时内创建一个答案。(抱歉,我现在得赶时间了)如果我没有swagger.json文件该怎么办?好吧,你的api应该以某种方式进行描述?如果没有,你希望api管理层如何导入它?我没有swagger.json文件,而是在位置-。当我放置这个路径时,它抛出了错误的请求。好吧,这个页面可能不仅仅返回一个json文件,对吗?你需要获取json文件,是吗在添加现有Azure Api应用程序的情况下,是否不使用swagger.json或reflector来解析程序集?