英文:
Entity with specified identifier not found when applying policy on API operation with Bicep in Azure API Management
问题
我想要将出站策略应用于我的API的某些操作。我使用一个Bicep文件来完成这个操作,但是我收到了以下错误信息:
"statusMessage": {
"status": "Failed",
"error": {
"code": "ValidationError",
"message": "指定的标识符对应的实体未找到"
}
}
这是策略的代码片段:
resource relationApiSym 'Microsoft.ApiManagement/service/apis@2022-08-01' existing = {
name: relationsApi.name
parent: apiManagementInstance
resource operationRegisterId 'operations@2022-08-01' existing = {
name: 'post-registerrelation-id'
resource policyId 'policies@2022-08-01' = {
name: 'policy'
properties: {
format: 'xml'
value:'<policies>\r\n<inbound>\r\n<base />\r\n</inbound>\r\n<backend>\r\n<base />\r\n</backend>\r\n<outbound>\r\n<base />\r\n<choose>\r\n<when condition="@(context.Response.StatusCode == 200)">\r\n<set-body>@{var response = context.Response.Body.As<JObject>();foreach (var key in new [] {"RelatieId"}) {response.Property (key).Remove ();}return response.ToString();}\r\n</set-body>\r\n</when>\r\n</choose>\r\n</outbound>\r\n<on-error>\r\n<base />\r\n</on-error>\r\n</policies>'
}
}
}
}
我注意到操作的名称是'post-register-relation-id',但当我检查部署日志中的目标URL时,我注意到没有策略(尚未)。
英文:
I would like to apply an outbound policy to some of the operations of my API. I use a Bicep file to accomplish that but I get the following error:
"statusMessage": {
"status": "Failed",
"error": {
"code": "ValidationError",
"message": "Entity with specified identifier not found"
}
}
This is the snippet for the policy:
resource relationApiSym 'Microsoft.ApiManagement/service/apis@2022-08-01' existing = {
name: relationsApi.name
parent: apiManagementInstance
resource operationRegisterId 'operations@2022-08-01' existing = {
name : 'post-registerrelation-id'
resource policyId 'policies@2022-08-01' = {
name: 'policy'
properties: {
format: 'xml'
value:'<policies>\r\n<inbound>\r\n<base />\r\n</inbound>\r\n<backend>\r\n<base />\r\n</backend>\r\n<outbound>\r\n<base />\r\n<choose>\r\n<when condition="@(context.Response.StatusCode == 200)">\r\n<set-body>@{var response = context.Response.Body.As&lt;JObject&gt;();foreach (var key in new [] {"RelatieId"}) {response.Property (key).Remove ();}return response.ToString();}\r\n</set-body>\r\n</when>\r\n</choose>\r\n</outbound>\r\n<on-error>\r\n<base />\r\n</on-error>\r\n</policies>'
}
}
}
}
I see that the operation exisits with the name 'post-register-relation-id' but when i check the target url from the deploymentlog, I notice that there are no policies (yet)
答案1
得分: 0
我已经使用了您的代码,并进行了一些修改,它对我起作用。
这里 afreen-apimgmt-001
是 Azure API Management 实例名称,echo-api
是 API 名称,create-resource
是我想应用策略的操作名称。
请确保您所选取的操作名称是正确的,并且在 Azure API 管理门户中存在。
英文:
I have used your code with few modifications and it worked for me.
Here afreen-apimgmt-001
is the Azure API Management instance name, echo-api
is the API name and create-resource
is the operation name where I want to apply the policy.
Make sure, the operation name you have taken is correct and present in Azure API management portal.
Code-
resource relationApiSym 'Microsoft.ApiManagement/service/apis@2022-08-01' existing = {
name: 'afreen-apimgmt-001/echo-api'
resource operationRegisterId 'operations@2022-08-01' existing = {
name : 'create-resource'
resource policyId 'policies@2022-08-01' = {
name: 'policy'
properties: {
format: 'xml'
value:'<policies>\r\n<inbound>\r\n<base />\r\n</inbound>\r\n<backend>\r\n<base />\r\n</backend>\r\n<outbound>\r\n<base />\r\n<choose>\r\n<when condition="@(context.Response.StatusCode == 200)">\r\n<set-body>@{var response = context.Response.Body.As&lt;JObject&gt;();foreach (var key in new [] {"RelatieId"}) {response.Property (key).Remove ();}return response.ToString();}\r\n</set-body>\r\n</when>\r\n</choose>\r\n</outbound>\r\n<on-error>\r\n<base />\r\n</on-error>\r\n</policies>'
}
}
}
}
Output-
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论