是的,你可以做到(有点小技巧)。为此,您必须使用 REST Api,特别是 call。对我来说,编辑现有 API 不起作用(它们的密钥仍然存在),但是当我创建新 API 时,密钥不存在:
我不得不把我所有的东西都弄模糊了,很抱歉。因此,要实现这一点,您需要发出以下查询:
路径:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}?api-version=2016-07-07&import=true&path={APIpostfix}
标题:
Authorization = "Bearer TOKEN_GOES_HERE" ## Space after 'Bearer' is mandatory
Content-Type = "application/vnd.swagger.link+json" ## Look for the proper "Content-Type" on the page I've linked. This is the example to import API definition directly from "swagger.json" generated by your running api.
主体:
{
"name": "Name",
"description": "Desc",
"link": "http://url.to/your/swagger.json", ## <<only needed if you import directly from running API
"serviceUrl": "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/backends/{APIpostfix}", ## << declare your API Management backend
"protocols": [
"https"
],
"authenticationSettings": {
"oAuth2": null,
"openid": null
},
"subscriptionKeyParameterNames": { ## << Magic happens here
"header": null,
"query": null
}
}
PS。我从来没有费心去弄清楚 PUT + Send 通过 swagger 文件,但是当您知道这一点时,我相信它非常简单。