首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用powershell将现有API添加到Azure API管理服务中

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

Stack Overflow用户
提问于 2017-03-27 06:45:55
回答 1查看 1.2K关注 0票数 2

我需要通过Powershell命令将现有(已部署的) API应用程序添加到API管理服务中。当我使用‘’命令尝试它时,它将创建新的API,但它没有导入这些操作。从文件或URL导入API有很多种方法,但是我需要添加现有的API,我遵循https://learn.microsoft.com/en-us/powershell/resourcemanager/apimanagement.servicemanagement/v1.1.4/new-azurermapimanagementapi链接,有没有方法将现有的API应用程序添加到API管理服务?

请求是-

代码语言:javascript
复制
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应用程序、名称作为参数的命令

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-27 08:39:56

因此,您可以通过描述这里的REST调用来实现这一点。

要获得承载令牌,请使用以下powershell代码:

代码语言:javascript
复制
$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调用:

代码语言:javascript
复制
$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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43039556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档